我首先我们查看当前的IP地址
[root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.19.235 netmask 255.255.255.0 broadcast 192.168.19.255 ether 00:0c:29:d7:f6:2f txqueuelen 1000 (Ethernet) RX packets 21094 bytes 2613064 (2.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 7348 bytes 892641 (871.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
接下来我们进行手动配置IP
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
根据网卡的不同,网卡名称也不一样,我们来配置基本的IP信息,写好后保存退出。
YTPE=Ethernet #网络类型
DEVICE=ens33 #网卡名称 NAME=ens33 #文件名称 ONBOOT=yes #是否开进启动 这里我们选择yes BOOTPROTO=none #自动获取IP 因为我们要手动配置IP地址,这里我们选择none
IPADDR=192.168.19.111 #下面是IP地址、掩码、网关和DNS NETMASK=255.255.255.0 GATEWAY=192.168.19.2 DNS1=114.114.114.114
重启一下网络服务, 有问题会报错。
[root@localhost ~]# systemctl restart network
[root@localhost ~]#
再次查看我们的IP是否已经换成我们修改过后的地址了?
[root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.19.111 netmask 255.255.255.0 broadcast 192.168.19.255 ether 00:0c:29:d7:f6:2f txqueuelen 1000 (Ethernet) RX packets 21272 bytes 2624571 (2.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 7386 bytes 897202 (876.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
已经变成了我们修改过得192.168.19.111
ping一下查看是否可以连接网络
[root@localhost ~]# ping www.baidu.com PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data. 64 bytes from www.baidu.com (61.135.169.121): icmp_seq=1 ttl=128 time=4.88 ms 64 bytes from www.baidu.com (61.135.169.121): icmp_seq=2 ttl=128 time=6.22 ms 64 bytes from www.baidu.com (61.135.169.121): icmp_seq=3 ttl=128 time=4.51 ms 64 bytes from www.baidu.com (61.135.169.121): icmp_seq=4 ttl=128 time=4.28 ms ^C --- www.a.shifen.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3005ms rtt min/avg/max/mdev = 4.283/4.975/6.222/0.750 ms
可以看到配置的网络地址成功了