查看IP
ifconfig
查看网络文件
vim /etc/sysconfig/network-scripts/
修改ens文件
vim /etc/sysconfig/network-scripts/ifcfg-ens33
添加以下配置
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
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=ens33
UUID=d9bbc3c6-4f1a-4c14-8a25-8488bffce199
DEVICE=ens33
ONBOOT="yes"
# 这个为静态IP
IPADDR=192.168.56.11
NETMASK=255.255.255.0
GATEWAY=192.168.56.2
重启网络服务
systemctl restart network
测试
ping 8.8.8.8
ping www.baidu.com
我们这里发现百度ping不通 是因为DNS有问题
配置DNS
vim /etc/resolv.conf
添加如下内容
nameserver 192.168.56.2
最后查看ip
ifconfig
[root@aubin ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:d6:ea:f2:7e txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.130 netmask 255.255.255.0 broadcast 192.168.56.255
inet6 fe80::8b02:e710:e394:90aa prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:28:fd:41 txqueuelen 1000 (Ethernet)
RX packets 789880 bytes 1117587089 (1.0 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 269183 bytes 16437186 (15.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 1360 bytes 150176 (146.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1360 bytes 150176 (146.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:7b:17:69 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]# ifconfig
[root@aubin ~]# vim /etc/sysconfig/network-scripts/
ifcfg-ens33 ifdown-Team ifup-post
ifcfg-lo ifdown-TeamPort ifup-ppp
ifdown ifdown-tunnel ifup-routes
ifdown-bnep ifup ifup-sit
ifdown-eth ifup-aliases ifup-Team
ifdown-ib ifup-bnep ifup-TeamPort
ifdown-ippp ifup-eth ifup-tunnel
ifdown-ipv6 ifup-ib ifup-wireless
ifdown-isdn ifup-ippp init.ipv6-global
ifdown-post ifup-ipv6 network-functions
ifdown-ppp ifup-isdn network-functions-ipv6
ifdown-routes ifup-plip
ifdown-sit ifup-plusb
[root@aubin ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]# systemctl restart network
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=128 time=66.5 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=128 time=114 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=128 time=71.5 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2007ms
rtt min/avg/max/mdev = 66.517/84.170/114.426/21.494 ms
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]# ping www.baidu.com
ping: www.baidu.com: 未知的名称或服务
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]# vim /etc/resolv.conf
[root@aubin ~]#
[root@aubin ~]#
[root@aubin ~]# ping www.baidu.com
PING www.a.shifen.com (110.242.68.4) 56(84) bytes of data.
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=1 ttl=128 time=71.2 ms
64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=2 ttl=128 time=80.5 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 71.237/75.900/80.564/4.671 ms
[root@aubin ~]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:d6:ea:f2:7e txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.11 netmask 255.255.255.0 broadcast 192.168.56.255
inet6 fe80::8b02:e710:e394:90aa prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:28:fd:41 txqueuelen 1000 (Ethernet)
RX packets 789926 bytes 1117590273 (1.0 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 269243 bytes 16443761 (15.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 1432 bytes 157176 (153.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1432 bytes 157176 (153.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:7b:17:69 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0