错误:网络掩码与路由地址不匹配

错误:网络掩码与路由地址不匹配

我正在尝试通过以下命令在 Ubuntu 16.04 中添加新路线:

sudo route add -net 192.168.245.2 netmask 255.255.255.0 gw 192.168.0.200 enp2s0

但出现此错误:

route: netmask doesn't match route address

问题是什么?

我目前的路线配置:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.2     0.0.0.0         UG    100    0        0 enp2s0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-5486059fe8de
192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 enp2s0

我的 ipconfig 是:

br-5486059fe8de Link encap:Ethernet  HWaddr 02:42:1d:f8:39:ff
          inet addr:172.18.0.1  Bcast:172.18.255.255  Mask:255.255.0.0
          inet6 addr: fe80::42:1dff:fef8:39ff/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1037540843 errors:0 dropped:0 overruns:0 frame:0
          TX packets:394316816 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:77880182834 (77.8 GB)  TX bytes:48906441136 (48.9 GB)

docker0   Link encap:Ethernet  HWaddr 02:42:4f:02:e5:d2
          inet addr:172.17.0.1  Bcast:172.17.255.255  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

enp2s0    Link encap:Ethernet  HWaddr e0:d5:5e:ae:93:c4
          inet addr:192.168.0.198  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::2916:649e:d2df:8977/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:115855891728 errors:0 dropped:0 overruns:0 frame:0
          TX packets:172768700525 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:38396265500942 (38.3 TB)  TX bytes:150008590086247 (150.0 TB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:3593837969 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3593837969 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1583904668749 (1.5 TB)  TX bytes:1583904668749 (1.5 TB)

veth11ef68d Link encap:Ethernet  HWaddr 2e:ba:5b:fe:83:63
          inet6 addr: fe80::2cba:5bff:fefe:8363/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1044675619 errors:0 dropped:0 overruns:0 frame:0
          TX packets:397896221 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:92919495264 (92.9 GB)  TX bytes:49214351956 (49.2 GB)

veth8ae1550 Link encap:Ethernet  HWaddr 8e:06:4c:93:db:1d
          inet6 addr: fe80::8c06:4cff:fe93:db1d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3567676 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7824931 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:306871120 (306.8 MB)  TX bytes:636363292 (636.3 MB)

答案1

您要么更改 ip,要么更改掩码,即:

sudo route add -net 192.168.245.0 netmask 255.255.255.0 gw 192.168.0.200 enp2s0

或者

sudo route add -net 192.168.245.2 netmask 255.255.255.255 gw 192.168.0.200 enp2s0

相关内容