ubuntu 获取ip由dhcp变成成static,需要重启机器dns才能更新?
发表于 : 2020-06-16 17:01
当前网卡接口的配置在/etc/net/interfaces如下:
auto enp2s0
iface enp2s0 inet dhcp
查看dns如下:
cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.0.193
nameserver 219.141.140.10
nameserver 219.141.136.10
现在将ip改成静态设置,配置dns为网关192.168.0.193:
auto enp2s0
iface enp2s0 inet static
address 192.168.0.130
netmask 255.255.255.0
gateway 192.168.0.193
dns-nameservers 192.168.0.193
重启服务:sudo ip addr flush && sudo systemctl restart networking.service
查看dns 仍然是dhcp自动生成的
cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.0.193
nameserver 219.141.140.10
nameserver 219.141.136.10
重启完机器后,再次查看dns,已经更新到192.168.0.193
cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.0.193
有什么方法可以不用重启电脑,让dns生效么
auto enp2s0
iface enp2s0 inet dhcp
查看dns如下:
cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.0.193
nameserver 219.141.140.10
nameserver 219.141.136.10
现在将ip改成静态设置,配置dns为网关192.168.0.193:
auto enp2s0
iface enp2s0 inet static
address 192.168.0.130
netmask 255.255.255.0
gateway 192.168.0.193
dns-nameservers 192.168.0.193
重启服务:sudo ip addr flush && sudo systemctl restart networking.service
查看dns 仍然是dhcp自动生成的
cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.0.193
nameserver 219.141.140.10
nameserver 219.141.136.10
重启完机器后,再次查看dns,已经更新到192.168.0.193
cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.0.193
有什么方法可以不用重启电脑,让dns生效么