目录
1、为网卡添加一个会话static,在此会话配置ip地址为x.x.x.123
2、测试网络连通性,看是否能够ping通百度,并把百度首页文件下载下来
一、思维导图
二、配置网络
1、为网卡添加一个会话static,在此会话配置ip地址为x.x.x.123
[root@localhost ~]# nmcli connection add type ethernet con-name static ifname ens160 ipv4.addresses 192.168.190.123 ipv4.gateway 192.168.190.2 ipv4.dns 8.8.8.8 ipv4.method manual
Connection 'static' (f1512086-abf6-4da3-90e6-a2a6994ac869) successfully added.
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-static
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.190.123
PREFIX=32
GATEWAY=192.168.190.2
DNS1=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=static
UUID=f1512086-abf6-4da3-90e6-a2a6994ac869
DEVICE=ens160
ONBOOT=yes
2、测试网络连通性,看是否能够ping通百度,并把百度首页文件下载下来
[root@localhost ~]# ping www.baidu.com -c 5
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=11.6 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=8.21 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=11.5 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128 time=9.40 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=128 time=11.3 ms
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4008ms
rtt min/avg/max/mdev = 8.209/10.391/11.569/1.354 ms
[root@localhost ~]# mkdir baidu
[root@localhost ~]# wget -P baidu www.baidu.com
--2022-10-30 19:45:46-- 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: ‘baidu/index.html’
index.html 100%[=====================================================>] 2.33K --.-KB/s in 0s
2022-10-30 19:45:46 (169 MB/s) - ‘baidu/index.html’ saved [2381/2381]
[root@localhost ~]# cd baidu
[root@localhost baidu]# ll
total 4
-rw-r--r--. 1 root root 2381 Oct 30 19:45 index.html
3、设置系统开机时,该网卡通过DHCP协议自动获取IP地址
[root@localhost ~]# nmcli connection modify static ipv4.method auto
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-static
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
IPADDR=192.168.190.123
PREFIX=32
GATEWAY=192.168.190.2
DNS1=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=static
UUID=f1512086-abf6-4da3-90e6-a2a6994ac869
DEVICE=ens160
ONBOOT=ye