安装network-manager
sudo apt update
sudo apt install network-manager
使用nmcli连接802.1X的wifi
root@mtr1:~# nmcli dev wifi
IN-USE BSSID SSID MODE CHAN RATE SIGNAL BARS SECURITY
F8:6F:B0:6D:CF:42 DMS-CEWS Infra 48 270 Mbit/s 100 ▂▄▆█ WPA2
6C:14:6E:9D:D6:62 -- Infra 44 260 Mbit/s 80 ▂▄▆_ WPA2 802.1X
6C:14:6E:9D:D6:60 -- Infra 44 260 Mbit/s 79 ▂▄▆_ WPA2 802.1X
6C:14:6E:9D:D6:61 -- Infra 44 260 Mbit/s 79 ▂▄▆_ WPA2 802.1X
5E:E7:47:D8:59:F0 DMR2323H0013A Infra 149 270 Mbit/s 72 ▂▄▆_ WPA2
F2:A7:31:2F:F5:D1 -- Infra 1 270 Mbit/s 69 ▂▄▆_ WPA2
F0:A7:31:2F:F5:D1 TP-Link_F5D1 Infra 1 270 Mbit/s 65 ▂▄▆_ WPA2
F0:A7:31:2F:F5:D0 TP-Link_F5D1_5G Infra 40 135 Mbit/s 47 ▂▄__ WPA2
* A8:BD:27:59:0D:F4 iWorld-AX Infra 116 540 Mbit/s 45 ▂▄__ WPA2 802.1X
A8:BD:27:59:0D:F1 iWorld Infra 116 540 Mbit/s 42 ▂▄__ WPA2 802.1X
A8:BD:27:59:0D:F2 WEN-dot1x Infra 116 540 Mbit/s 40 ▂▄__ WPA2 802.1X
A8:BD:27:59:0D:F0 -- Infra 116 540 Mbit/s 39 ▂▄__ WPA2
A8:BD:27:59:0D:F3 WEN-dot1x-pap Infra 116 540 Mbit/s 39 ▂▄__ WPA2 802.1X
A8:BD:27:59:0D:F5 -- Infra 116 540 Mbit/s 39 ▂▄__ WPA2 802.1X
配置:
##nmcli con add type wifi ifname [网卡名称] con-name [自定义名字 最好和SSID一致] ssid [WIFI-SSID]
# nmcli con add type wifi ifname wlx40a5ef24e92f con-name iWorld-AX ssid iWorld-AX
# nmcli con edit id iWorld-AX
nmcli> set wifi-sec.key-mgmt wpa-eap //设置安全类型,“wpa-eap”为WPA2企业
nmcli> set ipv4.method auto
nmcli> set 802-1x.eap peap //设置认证方式,PEAP版本为“自动”
nmcli> set 802-1x.phase2-auth mschapv2 //设置内部认证
nmcli> set 802-1x.identity ewsim //Username
nmcli> set 802-1x.password Polling002 //password
nmcli> save
nmcli> activate
设置开机连接
**nmcli connection modify IFNAME connection.autoconnect yes**
root@mtr2:~# nmcli connection modify iWorld-AX connection.autoconnect yes
设置静态IP
- 设置固定 IP 地址:使用
**nmcli connection modify**命令来修改连接配置,将其设置为固定 IP 地址。 - 例如,假设你要将接口名称为 eth0 的连接设置为固定 IP 地址为 192.168.1.100,网关为 192.168.1.1,DNS 服务器为 8.8.8.8,你可以执行以下命令:
**sudo nmcli connection modify eth0 ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns 8.8.8.8 ipv4.method manual**- 确保将命令中的 eth0 替换为你要设置的网络接口名称,以及将 IP 地址、网关和 DNS 服务器替换为你的实际配置。
- 重新启用连接:执行以下命令重新启用网络连接,使修改生效:
**sudo nmcli connection up eth0**
server1:
sudo nmcli connection modify iWorld-AX ipv4.addresses 192.168.227.27/18 ipv4.gateway 192.168.244.1 ipv4.dns 8.8.8.8 ipv4.method manual
server2:
sudo nmcli connection modify iWorld-AX ipv4.addresses 192.168.228.75/18 ipv4.gateway 192.168.244.1 ipv4.dns 8.8.8.8 ipv4.method manual
sudo nmcli connection up iWorld-AX
验证是否连接成功
root@mtr1:~# ip a | grep wlx
59: wlx200db0ce7c2c: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
inet 192.168.204.5/18 brd 192.168.255.255 scope global dynamic noprefixroute wlx200db0ce7c2c
root@mtr1:~# nmcli dev status
DEVICE TYPE STATE CONNECTION
wlx200db0ce7c2c wifi connected iWorld-AX
lo loopback connected (externally) lo
root@mtr2:~# ping -I wlx40a5ef24e92f www.baidu.com
PING www.wshifen.com (103.235.46.40) from 192.168.206.100 wlx40a5ef24e92f: 56(84) bytes of data.
64 bytes from 103.235.46.40 (103.235.46.40): icmp_seq=1 ttl=54 time=1027 ms
64 bytes from 103.235.46.40 (103.235.46.40): icmp_seq=3 ttl=54 time=7.24 ms
64 bytes from 103.235.46.40 (103.235.46.40): icmp_seq=4 ttl=54 time=7.94 ms
64 bytes from 103.235.46.40 (103.235.46.40): icmp_seq=5 ttl=54 time=6.11 ms
使用nmcli连接普通安全级别的的wifi
nmcli device wifi connect "SGNS_5G" password "sgns19519006535"