1、配置网络
(1)为网卡添加一个会话static,在此会话配置ip地址为x.x.x.123
[root@server ~]# nmcli connection s
NAME UUID TYPE DEVICE
ens160 6cd06fe2-c194-42a2-ad3f-d8de4b1104e0 ethernet ens160
virbr0 48ebb188-fb6c-4dfd-a23f-cdfb1904830d bridge virbr0
virbr0-nic 5a2ea478-6c13-431f-8d89-083598efdee0 tun virbr0-nic
[root@server ~]# nmcli connection add type ethernet con-name static ifname ens160 ipv4.method manual ipv4.addresses 10.10.0.123/24 ipv4.gateway 10.10.0.254 ipv4.dns 114.114.114.114 autoconnect yes
Connection 'static' (e7b26ebd-824d-4b20-8147-543f25427fea) successfully added.
[root@server ~]# nmcli connection show
NAME UUID TYPE DEVICE
ens160 6cd06fe2-c194-42a2-ad3f-d8de4b1104e0 ethernet ens160
virbr0 48ebb188-fb6c-4dfd-a23f-cdfb1904830d bridge virbr0
virbr0-nic 5a2ea478-6c13-431f-8d89-083598efdee0 tun virbr0-nic
static e7b26ebd-824d-4b20-8147-543f25427fea ethernet --
(2)测试网络连通性,看是否能够ping通百度,并把百度首页文件下载下来
[root@server ~]# ping www.baidu.com
PING www.a.shifen.com (183.232.231.174) 56(84) bytes of data.
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=1 ttl=128 time=41.1 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=2 ttl=128 time=58.6 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=4 ttl=128 time=55.9 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=5 ttl=128 time=32.2 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=6 ttl=128 time=32.8 ms
^C
--- www.a.shifen.com ping statistics ---
6 packets transmitted, 5 received, 16.6667% packet loss, time 70ms
rtt min/avg/max/mdev = 32.164/44.108/58.620/11.236 ms
[root@server ~]# wget http://www.baidu.com
--2022-11-01 19:52:11-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 183.232.231.172, 183.232.231.174
Connecting to www.baidu.com (www.baidu.com)|183.232.231.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html’
index.html 100%[=====================>] 2.33K --.-KB/s in 0s
2022-11-01 19:52:11 (532 MB/s) - ‘index.html’ saved [2381/2381]
[root@server ~]# ll ./index.html
-rw-r--r--. 1 root root 2381 Nov 1 19:52 ./index.html
(3)设置系统开机时,该网卡通过DHCP协议自动获取IP地址
[root@server ~]# nmcli connection modify ens160 ipv4.method auto
[root@server ~]# nmcli connection up ens160