确认当前网络配置:
[root@localhost ~]# nmcli -p dev ===================== Status of devices ===================== DEVICE TYPE STATE CONNECTION ------------------------------------------------------------------ virbr0 bridge connected virbr0 eth0 ethernet connected eth0 lo loopback unmanaged --
设置IP的文件修改如下:
## Configure eth0 # # vi /etc/sysconfig/network-scripts/ifcfg-eth0 HWADDR=00:0C:29:10:A0:DB MACADDR=00:0C:29:10:A0:DB TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no # Static IP Address # BOOTPROTO=static IPADDR=192.168.1.249 PREFIX=24 # Default Gateway IP # GATEWAY=192.168.1.1 # DNS Servers # DNS1=118.118.118.1 DEFROUTE=yes PEERDNS=no # Disable ipv6 # IPV4_FAILURE_FATAL=no IPV6INIT=no NAME=eth0 UUID=2734ae8a-4190-4cb9-9b32-4404dfc83e29 # Activate on Boot # ONBOOT=yes ## Configure Default Gateway # # vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=centos6 GATEWAY=192.168.1.1 ## Restart Network Interface # /etc/init.d/network restart ## Configure DNS Server # # vi /etc/resolv.conf nameserver 118.118.118.1 # Replace with your nameserver ip nameserver 192.168.1.1 # Replace with your nameserver ip
打开控制台,通过命令修改如下:
sudo ifconfig eth0 192.168.1.251 netmask 255.255.255.0 sudo route add default gw 192.168.1.1 sudo echo "nameserver 118.118.118.1" > /etc/resolv.conf sudo echo "nameserver 192.168.1.1" > /etc/resolv.conf
关闭防火墙及重启网络链接:
systemctl stop firewalld
systemctl disable firewalld
/etc/init.d/network restart
通过ifconfig命令查看当前IP,如未反映上时,可通过设置画面重启网络链接: