在Linux系统中Centos7设置静态ip的方法很简单,具体步骤如下:
1、编辑 ifcfg-eth0 文件,也有可能在你机器上不是显示的是eth0是enp12等其他。本文是ifcfg-eth0
vim /etc/sysconfig/network-scripts/ifcfg-enp4s0
2、修改如下内容
ONBOOT=yes #开机启用本配置 BOOTPROTO=static #dhcp改为static 静态IP IPADDR=10.120.10.59 #静态IP GATEWAY=10.120.10.252 #默认网关 NETMASK=255.255.255.0 #子网掩码 DNS1=202.103.24.68 #DNS 配置(有的话就可以配置)可选
3、重启下网络服务
service network restart 或 /etc/init.d/network restart
4、查看静态ip改动后的效果,在Centos 7系统中用的是ifconfig命令,而不是ipconfig命令,查询结果大致如下如下:
[root@VM_219_180_centos ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.120.10.59 netmask 255.255.255.0 broadcast 10.105.255.255 ether 52:54:00:f9:a0:20 txqueuelen 1000 (Ethernet) RX packets 100661461 bytes 11066300557 (10.3 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 93176575 bytes 73642656223 (68.5 GiB) 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 loop txqueuelen 1 (Local Loopback) 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