我的 /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
ens160:
dhcp4: no
dhcp6: no
addresses: [192.168.4.2/24, 192.168.4.3/24, 192.168.4.4/24, 192.168.4.5/24, 192.168.4.6/24, 192.168.4.7/24, 192.168.4.8/24, 192.168.4.9/24, 192.168.4.10/24, 192.168.4.11/24,]
gateway4: 192.168.4.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
我如何分配整个192.168.4.0/24子网到 NIC,网关和广播 IP 除外。
我希望能够使用子网中的所有 IP 地址,并将它们分配给我在 docker 中公开的不同端口。
除非我添加,否则我会收到此错误192.168.4.55/24到 netplan 中的地址,
我怎样才能继续添加整个子网,这样我就不必在 netplan 中手动添加该子网中的每个 IP?
答案1
对我有用的解决方案是:
我下载了一个IP生成器
然后我在 notepad++ 中打开了文本文件
这给了我需要添加到我的 netplan 的 IP 列表。
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
ens160:
dhcp4: no
dhcp6: no
addresses: [192.168.4.2/24, 192.168.4.3/24, 192.168.4.4/24, 192.168.4.5/24, 192.168.4.6/24, 192.168.4.7/24, 192.168.4.8/24, 192.168.4.9/24, 192.168.4.10/24, 192.168.4.11/24, 192.168.4.12/24, 192.168.4.13/24, 192.168.4.14/24, 192.168.4.15/24, 192.168.4.16/24, 192.168.4.17/24, 192.168.4.18/24, 192.168.4.19/24, 192.168.4.20/24, 192.168.4.21/24, 192.168.4.22/24, 192.168.4.23/24, 192.168.4.24/24, 192.168.4.25/24, 192.168.4.26/24, 192.168.4.27/24, 192.168.4.28/24, 192.168.4.29/24, 192.168.4.30/24, 192.168.4.31/24, 192.168.4.32/24, 192.168.4.33/24, 192.168.4.34/24, 192.168.4.35/24, 192.168.4.36/24, 192.168.4.37/24, 192.168.4.38/24, 192.168.4.39/24, 192.168.4.40/24, 192.168.4.41/24, 192.168.4.42/24, 192.168.4.43/24, 192.168.4.44/24, 192.168.4.45/24, 192.168.4.46/24, 192.168.4.47/24, 192.168.4.48/24, 192.168.4.49/24, 192.168.4.50/24, 192.168.4.51/24, 192.168.4.52/24, 192.168.4.53/24, 192.168.4.54/24, 192.168.4.55/24, 192.168.4.56/24, 192.168.4.57/24, 192.168.4.58/24, 192.168.4.59/24, 192.168.4.60/24, 192.168.4.61/24, 192.168.4.62/24, 192.168.4.63/24, 192.168.4.64/24, 192.168.4.65/24, 192.168.4.66/24, 192.168.4.67/24, 192.168.4.68/24, 192.168.4.69/24, 192.168.4.70/24, 192.168.4.71/24, 192.168.4.72/24, 192.168.4.73/24, 192.168.4.74/24, 192.168.4.75/24, 192.168.4.76/24, 192.168.4.77/24, 192.168.4.78/24, 192.168.4.79/24, 192.168.4.80/24, 192.168.4.81/24, 192.168.4.82/24, 192.168.4.83/24, 192.168.4.84/24, 192.168.4.85/24, 192.168.4.86/24, 192.168.4.87/24, 192.168.4.88/24, 192.168.4.89/24, 192.168.4.90/24, 192.168.4.91/24, 192.168.4.92/24, 192.168.4.93/24, 192.168.4.94/24, 192.168.4.95/24, 192.168.4.96/24, 192.168.4.97/24, 192.168.4.98/24, 192.168.4.99/24, 192.168.4.100/24, 192.168.4.101/24, 192.168.4.102/24, 192.168.4.103/24, 192.168.4.104/24, 192.168.4.105/24, 192.168.4.106/24, 192.168.4.107/24, 192.168.4.108/24, 192.168.4.109/24, 192.168.4.110/24, 192.168.4.111/24, 192.168.4.112/24, 192.168.4.113/24, 192.168.4.114/24, 192.168.4.115/24, 192.168.4.116/24, 192.168.4.117/24, 192.168.4.118/24, 192.168.4.119/24, 192.168.4.120/24, 192.168.4.121/24, 192.168.4.122/24, 192.168.4.123/24, 192.168.4.124/24, 192.168.4.125/24, 192.168.4.126/24, 192.168.4.127/24, 192.168.4.128/24, 192.168.4.129/24, 192.168.4.130/24, 192.168.4.131/24, 192.168.4.132/24, 192.168.4.133/24, 192.168.4.134/24, 192.168.4.135/24, 192.168.4.136/24, 192.168.4.137/24, 192.168.4.138/24, 192.168.4.139/24, 192.168.4.140/24, 192.168.4.141/24, 192.168.4.142/24, 192.168.4.143/24, 192.168.4.144/24, 192.168.4.145/24, 192.168.4.146/24, 192.168.4.147/24, 192.168.4.148/24, 192.168.4.149/24, 192.168.4.150/24, 192.168.4.151/24, 192.168.4.152/24, 192.168.4.153/24, 192.168.4.154/24, 192.168.4.155/24, 192.168.4.156/24, 192.168.4.157/24, 192.168.4.158/24, 192.168.4.159/24, 192.168.4.160/24, 192.168.4.161/24, 192.168.4.162/24, 192.168.4.163/24, 192.168.4.164/24, 192.168.4.165/24, 192.168.4.166/24, 192.168.4.167/24, 192.168.4.168/24, 192.168.4.169/24, 192.168.4.170/24, 192.168.4.171/24, 192.168.4.172/24, 192.168.4.173/24, 192.168.4.174/24, 192.168.4.175/24, 192.168.4.176/24, 192.168.4.177/24, 192.168.4.178/24, 192.168.4.179/24, 192.168.4.180/24, 192.168.4.181/24, 192.168.4.182/24, 192.168.4.183/24, 192.168.4.184/24, 192.168.4.185/24, 192.168.4.186/24, 192.168.4.187/24, 192.168.4.188/24, 192.168.4.189/24, 192.168.4.190/24, 192.168.4.191/24, 192.168.4.192/24, 192.168.4.193/24, 192.168.4.194/24, 192.168.4.195/24, 192.168.4.196/24, 192.168.4.197/24, 192.168.4.198/24, 192.168.4.199/24, 192.168.4.200/24, 192.168.4.201/24, 192.168.4.202/24, 192.168.4.203/24, 192.168.4.204/24, 192.168.4.205/24, 192.168.4.206/24, 192.168.4.207/24, 192.168.4.208/24, 192.168.4.209/24, 192.168.4.210/24, 192.168.4.211/24, 192.168.4.212/24, 192.168.4.213/24, 192.168.4.214/24, 192.168.4.215/24, 192.168.4.216/24, 192.168.4.217/24, 192.168.4.218/24, 192.168.4.219/24, 192.168.4.220/24, 192.168.4.221/24, 192.168.4.222/24, 192.168.4.223/24, 192.168.4.224/24, 192.168.4.225/24, 192.168.4.226/24, 192.168.4.227/24, 192.168.4.228/24, 192.168.4.229/24, 192.168.4.230/24, 192.168.4.231/24, 192.168.4.232/24, 192.168.4.233/24, 192.168.4.234/24, 192.168.4.235/24, 192.168.4.236/24, 192.168.4.237/24, 192.168.4.238/24, 192.168.4.239/24, 192.168.4.240/24, 192.168.4.241/24, 192.168.4.242/24, 192.168.4.243/24, 192.168.4.244/24, 192.168.4.245/24, 192.168.4.246/24, 192.168.4.247/24, 192.168.4.248/24, 192.168.4.249/24, 192.168.4.250/24, 192.168.4.251/24, 192.168.4.252/24, 192.168.4.253/24]
gateway4: 192.168.4.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]