Mar*_*tin 23 linux networking standard hosts
/etc/networks文件的实际用途是什么?据我了解,可以在此文件中为网络命名。例如:
root@fw-test:~# cat /etc/networks
default 0.0.0.0
loopback 127.0.0.0
link-local 169.254.0.0
google-dns 8.8.4.4
root@fw-test:~#
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试在ip实用程序中使用此网络名称,则它不起作用:
root@fw-test:~# ip route add google-dns via 104.236.63.1 dev eth0
Error: an inet prefix is expected rather than "google-dns".
root@fw-test:~# ip route add 8.8.4.4 via 104.236.64.1 dev eth0
root@fw-test:~#
Run Code Online (Sandbox Code Playgroud)
/etc/networks文件的实际用途是什么?
cha*_*aos 19
正如手册页中所写,该/etc/networks文件用于描述网络的符号名称。对于网络,是指.0末尾有拖尾的网络地址。仅支持简单的 A、B 或 C 类网络。
在您的示例中,google-dns输入错误。它不是 A、B 或 C 网络。它是一个 ip-address-hostname-relationship 因此它属于/etc/hosts. 实际上default条目也不符合。
假设您有一个192.168.1.5来自公司网络的 IP 地址。/etc/network然后输入可以是:
corpname 192.168.1.0
Run Code Online (Sandbox Code Playgroud)
使用route或 等实用程序时netstat,这些网络将被转换(如果您不使用-n标志抑制解析)。路由表可能如下所示:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
corpname * 255.255.255.0 U 0 0 0 eth0
Run Code Online (Sandbox Code Playgroud)
该ip命令也从不使用主机名进行输入,因此您的示例几乎不相关。此外,您已将主机名放入/etc/networks,而不是网络名!
条目来自/etc/networks尝试将数字转换为名称的工具,例如(不推荐使用的)route命令。如果没有合适的条目,它会显示:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.254 0.0.0.0 UG 0 0 0 eth0
192.168.0.0 * 255.255.254.0 U 0 0 0 eth0
Run Code Online (Sandbox Code Playgroud)
如果我现在添加一行mylocalnet 192.168.0.0到/etc/networks:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.254 0.0.0.0 UG 0 0 0 eth0
mylocalnet * 255.255.254.0 U 0 0 0 eth0
Run Code Online (Sandbox Code Playgroud)
在实践中,它从未真正使用过。
| 归档时间: |
|
| 查看次数: |
24902 次 |
| 最近记录: |