centos 7 静态IP,指定DNS
cd /etc/sysconfig/network-scripts/
找到对应的网卡,配置并编辑
ls -l
vim ifcfg-em1
配置例子:
TYPE="Ethernet"
#BOOTPROTO="dhcp"
BOOTPROTO=static
#配置静态IP,网关,子网掩码
IPADDR=192.168.42.4
NETMASK=255.255.255.0
GATEWAY=192.168.42.254
#取消networkmanager 管理
NM_CONTROLLED=no
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
NAME="em1"
UUID="24d12c22-f60d-4701-8105-a20f784b2825"
DEVICE="em1"
ONBOOT="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_PRIVACY="no"
NM_CONTROLLED=no表示该接口不通过网络管理器进行管理,而是通过配置文件管理。
“ONBOOT=yes”表示系统将在启动时开启该接口。
配置完静态IP后重启网络服务
systemctl restart network.service
接下来配置DNS切到networkmanager目录
cd /etc/NetworkManager/
修改 NetworkManager.conf配置文件,设定为不通过网络管理器管理
vim NetworkManager.conf
增加dns=none
修改resolv.conf,
vim /etc/resolv.conf
新增dns配置
#主DNS
nameserver 203.186.94.20
#备DNS2
#备DNS
nameserver 203.186.96.33
nameserver 8.8.8.8
转载http://www.centoscn.com/CentOS/config/2017/0508/8773.html
*************************************************快速一览**********************************************************************************************
cd /etc/sysconfig/network-scripts/
ls -l
vim ifcfg-em1
echo 'TYPE="Ethernet" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo '#BOOTPROTO="dhcp" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'BOOTPROTO=static ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo '#配置静态IP,网关,子网掩码 ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'IPADDR=192.168.42.4 ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'NETMASK=255.255.255.0 ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'GATEWAY=192.168.42.254 ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo '#取消networkmanager 管理 ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'NM_CONTROLLED=no ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'DEFROUTE="yes" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'IPV4_FAILURE_FATAL="no" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'IPV6INIT="yes" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'IPV6_AUTOCONF="yes" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'IPV6_DEFROUTE="yes" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'IPV6_FAILURE_FATAL="no" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'NAME="em1" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'UUID="24d12c22-f60d-4701-8105-a20f784b2825" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'DEVICE="em1" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'ONBOOT="yes" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'PEERDNS="yes" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'PEERROUTES="yes" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'IPV6_PEERDNS="yes" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'IPV6_PEERROUTES="yes" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo 'IPV6_PRIVACY="no" ' >> /etc/sysconfig/network-scripts/ifcfg-em1
echo '#配置完静态IP后重启网络服务 ' >> /etc/sysconfig/network-scripts/ifcfg-em1
systemctl restart network.service
配置networkmanager目录
echo 'dns=none" >> /etc/NetworkManager/NetworkManager.conf
修改
echo '#新增dns配置' > /etc/resolv.conf
echo '#主DNS ' >> /etc/resolv.conf
echo 'nameserver 203.186.94.20' >> /etc/resolv.conf
echo '#备DNS ' >> /etc/resolv.conf
echo 'nameserver 203.186.96.33' >> /etc/resolv.conf
echo '#备DNS2' >> /etc/resolv.conf
echo 'nameserver 8.8.8.8' >> /etc/resolv.conf