配置网络
(1)为网卡添加一个会话static,在此会话配置ip地址为x.x.x.123
[root@localhost network-scripts]# nmcli connection add type ethernet con-name static ifname ens192 ipv4.addresses '192.168.123.123/24' ipv4.routes '192.168.0.0/16' ipv4.gateway 192.168.123.154 ipv4.dns '8.8.8.8' ipv4.method manual autoconnect yes
Connection 'static' (fd1067f8-9ca7-43be-a783-d3e7792ca85e) successfully added.
[root@localhost network-scripts]# nmcli connection up static
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@localhost network-scripts]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:3a:e9:ff brd ff:ff:ff:ff:ff:ff
inet 192.168.182.131/24 brd 192.168.182.255 scope global dynamic noprefixroute ens160
valid_lft 1696sec preferred_lft 1696sec
inet6 fe80::20c:29ff:fe3a:e9ff/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:43:66:c3 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:43:66:c3 brd ff:ff:ff:ff:ff:ff
5: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:3a:e9:09 brd ff:ff:ff:ff:ff:ff
inet 192.168.123.123/24 brd 192.168.123.255 scope global noprefixroute ens192
valid_lft forever preferred_lft forever
inet6 fe80::6a04:dc4b:ab45:d61d/64 scope link noprefixroute
valid_lft forever preferred_lft forever
(2)测试网络连通性,看是否能够ping通百度,并把百度首页文件下载下来
[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=6.59 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=9.67 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=9.42 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128 time=9.19 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 6.586/8.715/9.672/1.246 ms
[root@localhost test]# wget -r www.baidu.com -P /test/wget
--2022-11-01 06:25:02-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 14.215.177.38, 14.215.177.39
Connecting to www.baidu.com (www.baidu.com)|14.215.177.38|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘/test/wget/www.baidu.com/index.html’
www.baidu.com/index.htm 100%[==============================>] 2.33K --.-KB/s in 0s
2022-11-01 06:25:02 (471 MB/s) - ‘/test/wget/www.baidu.com/index.html’ saved [2381/2381]
Loading robots.txt; please ignore errors.
--2022-11-01 06:25:02-- http://www.baidu.com/robots.txt
Reusing existing connection to www.baidu.com:80.
HTTP request sent, awaiting response... 200 OK
Length: 2814 (2.7K) [text/plain]
Saving to: ‘/test/wget/www.baidu.com/robots.txt’
www.baidu.com/robots.tx 100%[==============================>] 2.75K --.-KB/s in 0s
2022-11-01 06:25:02 (252 MB/s) - ‘/test/wget/www.baidu.com/robots.txt’ saved [2814/2814]
FINISHED --2022-11-01 06:25:02--
Total wall clock time: 0.06s
Downloaded: 2 files, 5.1K in 0s (320 MB/s)
[root@localhost test]# ll -d /test/wget
drwxr-xr-x. 3 root root 27 Nov 1 06:25 /test/wget