【Centos】通过修改配置文件配置IP和DNS地址

1、修改IP地址:

打开修改配置文件:

vim /etc/sysconfig/network-scripts/ifcfg-eth0

# Generated by dracut initrd 
DEVICE="eth0" 
ONBOOT="yes" 
IPV6INIT="no" 
IPV4_FAILURE_FATAL="no" 
NM_CONTROLLED="no" 
TYPE="Ethernet" 
BOOTPROTO="dhcp"

改为如下内容:

# Generated by dracut initrd 
DEVICE="eth0" 
ONBOOT="yes" 
IPV6INIT="no" 
IPV4_FAILURE_FATAL="no" 
NM_CONTROLLED="no" 
TYPE="Ethernet" 
BOOTPROTO="static" //静态获取 
IPADDR="192.168.1.10" //IP地址 
NETMASK="255.255.255.0" //子网掩码 
GATEWAY="192.168.1.254" //网关地址

重启服务:

systemctl restart network

2、修改DNS:

vim /etc/resolv.conf

写入:

nameserver 114.114.114.114

上一篇:Linux常用网络命令


下一篇:常用c语言函数