新系统的网络配置
一、查看网卡配置信息
[root@localhost /]# ip ad 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: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:36:a0:09 brd ff:ff:ff:ff:ff:ff inet 192.168.249.133/24 brd 192.168.249.255 scope global noprefixroute dynamic ens32 valid_lft 1738sec preferred_lft 1738sec inet6 fe80::989a:b11f:f6cc:ccfe/64 scope link noprefixroute valid_lft forever preferred_lft forever
显示该虚拟机的网卡名称为:ens32,并且已经配置过IP信息。
二、配置网卡
[root@localhost /]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
按 i 进入编辑模式,将文件修改为:
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="ens32" UUID="07e2f4f9-0373-46ec-8314-265be39166e0" DEVICE="ens32" ONBOOT="yes" IPADDR=192.168.249.134 NETMASK=255.255.255.0 GATEWAY=192.168.249.1 DNS1=114.114.114.114
按 ESC 键进入命令模式,输入“:x”保存并退出。
三、重启网卡,查看网络配置是否生效。
重启网络服务
[root@localhost ~]# systemctl restart network
查看IP信息是否已经更新
[root@localhost ~]# ip ad 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: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:36:a0:09 brd ff:ff:ff:ff:ff:ff inet 192.168.249.134/24 brd 192.168.249.255 scope global noprefixroute ens32 valid_lft forever preferred_lft forever inet6 fe80::989a:b11f:f6cc:ccfe/64 scope link noprefixroute valid_lft forever preferred_lft forever
验证网络的连通性
[root@localhost ~]# ping www.cnblogs.com PING www.cnblogs.com (121.40.43.188) 56(84) bytes of data. 64 bytes from 121.40.43.188 (121.40.43.188): icmp_seq=1 ttl=128 time=28.7 ms 64 bytes from 121.40.43.188 (121.40.43.188): icmp_seq=2 ttl=128 time=29.7 ms 64 bytes from 121.40.43.188 (121.40.43.188): icmp_seq=3 ttl=128 time=29.4 ms 64 bytes from 121.40.43.188 (121.40.43.188): icmp_seq=4 ttl=128 time=33.5 ms ^C --- www.cnblogs.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3013ms rtt min/avg/max/mdev = 28.704/30.349/33.560/1.893 ms
至此,新系统网卡配置完成!