linux系统设置静态dns
查看dns
cat /etc/resolv.conf
查看是否使用静态dns
cat /etc/sysconfig/network-scripts/ifcfg-eth0
设置使用静态dns
echo "PEERDNS=no" >> /etc/sysconfig/network-scripts/ifcfg-eth0
设置dns,实时生效。
echo "nameserver 223.5.5.5" >> /etc/resolv.conf
echo "nameserver 223.6.6.6" >> /etc/resolv.conf
重启网络
/etc/init.d/network restart
如果重启网络后 resolv.conf dns 设置自动消失,那么可以把dns添加到 ifcfg-eth0
echo "DNS1=223.5.5.5" >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo "DNS2=223.6.6.6" >> /etc/sysconfig/network-scripts/ifcfg-eth0
如果重启网络后 resolv.conf dns 设置自动消失,那么可以把dns添加到 ifcfg-eth0
echo "DNS1=223.5.5.5" >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo "DNS2=223.6.6.6" >> /etc/sysconfig/network-scripts/ifcfg-eth0