设置新的 Ubuntu 16 64 位服务器。需要将完整的 /22 IPv4 绑定为静态。我只能从外部 ping 通 .2,但不能 ping 其余部分,我被困在这里。
auto eno1
iface eno1 inet static
address xxx.xxx.16.2
netmask 255.255.252.0
network xxx.xxx.16.0
broadcast xxx.xxx.19.255
gateway xxx.xxx.16.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 8.8.8.8 8.8.4.4
dns-search domain.com
这种方法行不通
root@server:~# ip addr add xxx.xxx.16.1/22 dev eno1
root@server:~# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether d4:be:d9:ed:fb:8a brd ff:ff:ff:ff:ff:ff
inet xxx.xxx.16.2/22 brd xxx.xxx.19.255 scope global eno1
valid_lft forever preferred_lft forever
inet xxx.xxx.16.1/22 scope global secondary eno1
valid_lft forever preferred_lft forever
inet6 fe80::d6be:d9ff:feed:fb8a/64 scope link
valid_lft forever preferred_lft forever
3: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether d4:be:d9:ed:fb:8c brd ff:ff:ff:ff:ff:ff
4: eno3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether d4:be:d9:ed:fb:8e brd ff:ff:ff:ff:ff:ff
5: eno4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether d4:be:d9:ed:fb:90 brd ff:ff:ff:ff:ff:ff
root@server:~# ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet xxx.xxx.16.2 netmask 255.255.252.0 broadcast xxx.xxx.19.255
inet6 fe80::d6be:d9ff:feed:fb8a prefixlen 64 scopeid 0x20<link>
ether d4:be:d9:ed:fb:8a txqueuelen 1000 (Ethernet)
RX packets 28742 bytes 1879979 (1.8 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 989 bytes 112470 (112.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
答案1
您只能将一个地址绑定到一个接口,它不会接受网络。如果您想绑定更多地址,则需要创建虚拟接口,如下所示:
sudo ifconfig eno1:0 123.123.16.3/22 up
sudo ifconfig eno1:1 123.123.16.4/22 up
执行 1024 次,您的网络就设置好了。我建议编写一个脚本并将其添加到启动中。如果您需要进行更多配置,请查看 ifconfig 的手册页。
您还可以在 /etc/network/interfaces 文件中配置虚拟接口(也称为网络别名):
auto eno1:0
iface eno1:0 inet static
address xxx.xxx.16.3
....
auto eno1:1
iface eno1:1 inet static
address xxx.xxx.16.4
然后重复。你最好编写一个自定义脚本,如果你需要更改任何简单的查找/替换无法处理的内容,管理这个巨大的文件将是一场噩梦。