“模板:使用nmcli命令配置网络”的版本间的差异
来自ARM Wiki
Sunxiaolin(讨论 | 贡献) (创建页面,内容为“===使用nmcli命令配置网络=== 查看已创建的连接: <syntaxhighlight lang="bash"> nmcli connection show </syntaxhighlight> 查看网络接口状态:...”) |
Sunxiaolin(讨论 | 贡献) (→使用nmcli命令配置网络) |
||
第1行: | 第1行: | ||
===使用nmcli命令配置网络=== | ===使用nmcli命令配置网络=== | ||
+ | |||
+ | ====设置静态IP示例==== | ||
查看已创建的连接: | 查看已创建的连接: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
nmcli connection show | nmcli connection show | ||
+ | ... | ||
+ | 有线连接 1 36ff5fe1-088a-3562-a9f1-70e9552ce8b6 ethernet eth0 | ||
+ | ... | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 若已存在关于网络接口eth0的连接,需先删除: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli | + | nmcli connection delete '有线连接 1' |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 添加名为''my_static_eth0''的静态IP连接: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli | + | nmcli connection add con-name my_static_eth0 ifname eth0 type ethernet ip4 10.168.1.157/24 gw4 10.168.1.1 |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 设置DNS: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli | + | nmcli connection modify my_static_eth0 ipv4.dns "10.168.1.1 119.29.29.29" |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ====设置动态IP示例==== | |
− | |||
− | |||
− | |||
− | + | 查看已创建的连接: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli connection | + | nmcli connection show |
+ | ... | ||
+ | 有线连接 1 36ff5fe1-088a-3562-a9f1-70e9552ce8b6 ethernet eth0 | ||
+ | ... | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 若已存在关于网络接口eth0的连接,需先删除: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli connection | + | nmcli connection delete '有线连接 1' |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 添加名为''my_dynamic_eth0''的动态IP连接: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli connection | + | nmcli connection add con-name my_dynamic_eth0 ifname eth0 type ethernet |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ====连接WIFI示例==== | |
− | |||
− | |||
− | |||
− | + | 查看WIFI网络列表: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli | + | nmcli device wifi list |
+ | ... | ||
+ | IN-USE SSID MODE CHAN RATE SIGNAL BARS SECURITY | ||
+ | OrayBox-3D28 红外 9 130 Mbit/s 65 ▂▄▆_ WPA2 | ||
+ | NORCO-5G 红外 1 130 Mbit/s 59 ▂▄▆_ WPA2 | ||
+ | ... | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 连接名为''OrayBox-3D28''密码为''norco85258506''的WIFI: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli | + | nmcli device wifi connect OrayBox-3D28 password norco85258506 |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | ====其他命令==== | |
− | |||
− | |||
− | |||
+ | 查看网络接口状态: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | nmcli device status | |
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | 查看网络接口网络信息: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | nmcli device show eth0 | |
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 使用连接: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli connection | + | nmcli connection up my_static_eth0 |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | 不使用连接: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | nmcli connection down my_static_eth0 | |
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 查看连接详细信息: | |
− | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli | + | nmcli connection show my_static_eth0 |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 关闭WIFI: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli | + | nmcli radio wifi off |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | 打开WIFI: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | nmcli radio wifi on | |
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 连接WIFI并设置静态IP: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli con add con-name my_wifi type wifi ifname wlan0 ssid " | + | nmcli con add con-name "my_wifi" type wifi ifname wlan0 ssid "OrayBox-3D28" -- wifi-sec.key-mgmt wpa-psk wifi-sec.psk "norco85258506" ipv4.method manual ipv4.address 10.168.1.158/24 ipv4.dns 119.29.29.29 ipv4.gateway 10.168.1.1 |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 创建名为''my_hotspot''的WIFI热点: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | nmcli dev wifi hotspot ifname wlan0 ssid | + | nmcli dev wifi hotspot ifname wlan0 ssid "my_hotspot" password "88888888" |
</syntaxhighlight> | </syntaxhighlight> |
2023年2月13日 (一) 11:57的版本
使用nmcli命令配置网络
设置静态IP示例
查看已创建的连接:
nmcli connection show
...
有线连接 1 36ff5fe1-088a-3562-a9f1-70e9552ce8b6 ethernet eth0
...
若已存在关于网络接口eth0的连接,需先删除:
nmcli connection delete '有线连接 1'
添加名为my_static_eth0的静态IP连接:
nmcli connection add con-name my_static_eth0 ifname eth0 type ethernet ip4 10.168.1.157/24 gw4 10.168.1.1
设置DNS:
nmcli connection modify my_static_eth0 ipv4.dns "10.168.1.1 119.29.29.29"
设置动态IP示例
查看已创建的连接:
nmcli connection show
...
有线连接 1 36ff5fe1-088a-3562-a9f1-70e9552ce8b6 ethernet eth0
...
若已存在关于网络接口eth0的连接,需先删除:
nmcli connection delete '有线连接 1'
添加名为my_dynamic_eth0的动态IP连接:
nmcli connection add con-name my_dynamic_eth0 ifname eth0 type ethernet
连接WIFI示例
查看WIFI网络列表:
nmcli device wifi list
...
IN-USE SSID MODE CHAN RATE SIGNAL BARS SECURITY
OrayBox-3D28 红外 9 130 Mbit/s 65 ▂▄▆_ WPA2
NORCO-5G 红外 1 130 Mbit/s 59 ▂▄▆_ WPA2
...
连接名为OrayBox-3D28密码为norco85258506的WIFI:
nmcli device wifi connect OrayBox-3D28 password norco85258506
其他命令
查看网络接口状态:
nmcli device status
查看网络接口网络信息:
nmcli device show eth0
使用连接:
nmcli connection up my_static_eth0
不使用连接:
nmcli connection down my_static_eth0
查看连接详细信息:
nmcli connection show my_static_eth0
关闭WIFI:
nmcli radio wifi off
打开WIFI:
nmcli radio wifi on
连接WIFI并设置静态IP:
nmcli con add con-name "my_wifi" type wifi ifname wlan0 ssid "OrayBox-3D28" -- wifi-sec.key-mgmt wpa-psk wifi-sec.psk "norco85258506" ipv4.method manual ipv4.address 10.168.1.158/24 ipv4.dns 119.29.29.29 ipv4.gateway 10.168.1.1
创建名为my_hotspot的WIFI热点:
nmcli dev wifi hotspot ifname wlan0 ssid "my_hotspot" password "88888888"