在 debian linux 上更改并同步主机名/IP 地址更改
为了更改静态IP地址,我设置了/etc/network/interfaces
的内容,
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet static
address <newaddress>
netmask <netmask>
gateway <gateway>
dns-nameservers <dns1> <dns2>
然后执行ifdown eth0 && ifup eth0
为了更改主机名,我执行以下操作
执行 hostname
设置 /etc/hostname
的内容将
/etc/hosts
中的
替换为
问题
IP 地址和主机名更改均不生效。
如果我更改 IP 地址并 ping 主机名,它仍然解析为旧地址
如果我更改主机名并 ping 新主机名,它无法解析为 IP
如果我更改主机名并 ping 旧主机名,它仍然可用并且解析当前ip地址。
我重新启动机器,它的行为仍然相同。
我缺少什么?
父网络可以在其中发挥任何作用吗?
另请注意,我的机器认为主机名在我更改后已更新。
For changing static ip address, i set the contents of /etc/network/interfaces
to
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet static
address <newaddress>
netmask <netmask>
gateway <gateway>
dns-nameservers <dns1> <dns2>
then do ifdown eth0 && ifup eth0
For changing the hostname, i do the following actions
execute hostname <newname>
set contents of /etc/hostname
to <newname>
replace <oldname>
with <newname>
in /etc/hosts
Issues
Both ip address and host name changes don't take effect.
If I change the ip address and ping the hostname, it still resolves to the oldaddress
If I change the hostname and ping the new hostname, it cannot resolve to an ip
If I change the hostname and ping the old hostname, it is still available and resolved the current ip address.
I restart the machine and it still behaves the same way.
What am I missing?
Could the parent network play any role in this?
Also note that my machine thinks the hostname is updated after I change it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这实际上不是问题,这种行为可以通过 arp 缓存来解释。
ARP 工具操纵或显示内核的 IPv4 网络邻居,这在某种程度上也包括您的主机。
arp 命令有许多可以使用的开关,例如以下命令:
该命令打印 arp 缓存条目列表。
不幸的是,没有命令可以刷新它,因此,您有两个选择。
选项 1:等待缓存更新(不会花很长时间)
选项 2:运行以下非常基本的脚本,您会看到:
该脚本不是我的,我报告了我通常运行的唯一脚本,该脚本最初来自这个做得很好的例子:
http://www.lainoox.com/display-add-flush-arpcache-linux-arp/
我希望这会有所帮助。
I think this is not actually a problem and this behavior is explained by arp caching.
The ARP tool manipulates or displays the kernel's IPv4 network neighbour and this includes in some way your host as well.
The arp command has many switches you can work on as, for example, the following command:
This command prints out the list of arp cache entries.
Unfortunately there is no command to flush it hence, you have 2 options.
Option 1: You wait for the cache to update (won't take long)
Option 2: You run the following very basic script and you see:
The script is not mine, I have reported the only I usually run which was taken originally from this well done example:
http://www.lainoox.com/display-add-flush-arpcache-linux-arp/
I hope this helps in some way.
更改 /etc/hostname 将影响显示在终端、欢迎消息、日志以及系统使用主机名的任何其他位置上的主机名。这些都是虚荣的改变。
更改 /etc/hosts 将更改您的本地主机名解析(即将 IP 地址转换为主机名,反之亦然)任何 DNS 无法解析的内容或您想要在本地覆盖的任何内容。默认情况下,本地文件覆盖网络分辨率。这是在 /etc/nsswitch 中确定的,它表示首先使用本地文件,然后使用 dns 进行主机解析。
这里要记住的重要一点是,这些更改不会影响网络上的其他人如何确定该主机的 IP 地址或名称,这当然是通过 DNS 或本地 /etc/ 处理的主机文件。
Changing /etc/hostname will have the affect of changing the hostname displayed on your terminal, welcome messages, in your logs and anywhere else the system uses
hostname
. These are all vanity changes.Channging /etc/hosts will change your local host-name resolution (i.e. translating an ip address to a hostname and vise versa) Anything DNS does not resolv or anything you want to override locally. By default, the local files override network resolution. This is determined in /etc/nsswitch which says to use local files first then then dns for host resolution.
The important thing to keep in mind here is that these changes will not affect how othesr on a network would determine this host's ip address or name, which of course is handled through DNS or maybe their local /etc/hosts file(s).
是的,resolv.conf 用于 dns。原样处理 NAMES 以及与互联网有关的任何内容。比如ping。 dns resolvc 本地天气您是否有服务器,因此主机名/等也处理 dns 的主机。当您连接时,您的 resolv.conf 将从您的 ISP 更新,或者您可以手动更改它/在桥接接口上设置一些更动态的内容
yeah resolv.conf is for dns. as is which handles NAMES and anything that has to do with the internet. Such as ping. dns resolvc locally weather you have server or not thus the hostname / ect hosts which ALSO handle dns. your resolv.conf will update from your isp when you connect or you can change it by hand / set some thing more dynamic on a bridged interface