centos7 配置静态ip
centos7 跟centos6有一些不同的
查看你的网络接口哪些受网络管理器管理
[root@zhangxs network-scripts]# nmcli dev status DEVICE TYPE STATE CONNECTION virbr0 bridge connected virbr0 enp1s0f0 ethernet connected enp1s0f0 //这个是我系统默认的网卡名 wlp2s0 wifi connected newifi_B5E0 lo loopback unmanaged -- virbr0-nic tun unmanaged --
vi etc/sysconfig/network-scripts/ifcfg-enp1s0f0
TYPE=Ethernet BOOTPROTO=static //原是dhcp,改为static DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=enp1s0f0 UUID=f032d1e7-ccca-49c7-a845-5a02c404694b DEVICE=enp1s0f0 ONBOOT=yes //原no,改为yes IPADDR=192.168.177.120 // 新增 GATEWAY=192.168.99.12 // 新增:注意,这个网官“99”是我的路由器的网关,你要修改为你自己的网官 NETMASK=255.255.255.0 // 新增 NM_CONTROLLED=no // 新增 DNS1=8.8.8.8 // 新增 DNS2=8.8.4.4 // 新增
保存以上配置
重起你的网络管理器
systemctl restart network.service
ifconfig 查看,已经配置成功
[root@zhangxs network-scripts]# ifconfig enp1s0f0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.177.120 netmask 255.255.255.0 broadcast 192.168.177.255 ether f8:a9:63:04:42:7e 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 device interrupt 18
ping www.baidu.com ok配置完成
[root@zhangxs network-scripts]# ping www.baidu.com PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data. 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=53 time=44.7 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=53 time=24.9 ms