SIOCADDRT:尝试添加路由时网络无法访问

问题描述

这是来自 Ubuntu 的 ifconfig:

eno1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether ac:1f:6b:3c:60:c4  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno2: flags=4163<UP,RUNNING,MULTICAST>  mtu 1500
        inet 10.134.50.124  netmask 255.255.255.0  broadcast 10.134.50.255
        inet6 fe80::c94e:c0f0:2149:ce10  prefixlen 64  scopeid 0x20<link>
        ether ac:1f:6b:3c:60:c5  txqueuelen 1000  (Ethernet)
        RX packets 116239544  bytes 98775856318 (98.7 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 38366240  bytes 7250711499 (7.2 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 1094335  bytes 262320880 (262.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1094335  bytes 262320880 (262.3 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:f9:60:b6  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vmnet1: flags=4163<UP,MULTICAST>  mtu 1500
        inet 172.16.212.1  netmask 255.255.255.0  broadcast 172.16.212.255
        inet6 fe80::54af:eff1:f932:d2b8  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:c0:00:01  txqueuelen 1000  (Ethernet)
        RX packets 4002  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 151408  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vmnet8: flags=4163<UP,MULTICAST>  mtu 1500
        inet 192.168.36.1  netmask 255.255.255.0  broadcast 192.168.36.255
        inet6 fe80::bba6:8b54:ddcf:8499  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:c0:00:08  txqueuelen 1000  (Ethernet)
        RX packets 4214  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 152463  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

这是来自 Windows 的 ipconfig(使用 Cygwin):

Windows IP Configuration


Ethernet adapter Ethernet:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : cwnow.local

Ethernet adapter VirtualBox Host-Only Network:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::d8fb:7a9d:b018:8399%20
   IPv4 Address. . . . . . . . . . . : 192.168.56.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 

Ethernet adapter Npcap Loopback Adapter:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::927:546c:aa9d:f57e%19
   Autoconfiguration IPv4 Address. . : 169.254.245.126
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . : 

Wireless LAN adapter Local Area Connection* 1:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 

Wireless LAN adapter Local Area Connection* 3:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 

Ethernet adapter VMware Network Adapter VMnet1:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::a941:328d:af54:6a14%12
   IPv4 Address. . . . . . . . . . . : 192.168.146.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 

Ethernet adapter VMware Network Adapter VMnet8:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::9ed:bfc8:373c:3ce6%2
   IPv4 Address. . . . . . . . . . . : 192.168.195.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : 
   Link-local IPv6 Address . . . . . : fe80::fcfd:d9cc:e5ba:3c31%13
   IPv4 Address. . . . . . . . . . . : 10.134.52.220
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 10.134.52.196

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : 

当我在 Windows 机器上时,我可以 ping Ubuntu 机器:

$ ping -c 3 10.134.50.124
PING 10.134.50.124 (10.134.50.124): 56 data bytes
64 bytes from 10.134.50.124: icmp_seq=0 ttl=62 time=3.011 ms
64 bytes from 10.134.50.124: icmp_seq=1 ttl=62 time=4.598 ms
64 bytes from 10.134.50.124: icmp_seq=2 ttl=62 time=2.967 ms
--- 10.134.50.124 ping statistics ---
3 packets transmitted,3 packets received,0% packet loss
round-trip min/avg/max/stddev = 2.967/3.525/4.598/0.759 ms

但我无法从 Ubuntu 机器 ping Windows 机器:

$ ping -c 3 10.134.52.220
PING 10.134.52.220 (10.134.52.220) 56(84) bytes of data.

--- 10.134.52.220 ping statistics ---
3 packets transmitted,0 received,100% packet loss,time 2080ms

我在 Ubuntu 机器上尝试了一些 route 命令,但没有成功:

$ route add -host 10.134.52.220 gw 10.134.52.196
SIOCADDRT: Operation not permitted
$ route add -host 10.134.52.220 gw 10.134.52.196 netmask 255.255.248.0
route: netmask 000007ff doesn't make sense with host route
$ route add -host 10.134.52.220/24 gw 10.134.52.196
route: netmask 000000ff doesn't make sense with host route
$ route add -host 10.134.52.220/21 gw 10.134.52.196
route: netmask 000007ff doesn't make sense with host route

这是 Ubuntu 上的路由表:

$ netstat -ar
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         _gateway        0.0.0.0         UG        0 0          0 eno2
10.134.50.0     0.0.0.0         255.255.255.0   U         0 0          0 eno2
10.134.52.220   _gateway        255.255.255.255 UGH       0 0          0 eno2
link-local      0.0.0.0         255.255.0.0     U         0 0          0 eno2
172.16.212.0    0.0.0.0         255.255.255.0   U         0 0          0 vmnet1
192.168.36.0    0.0.0.0         255.255.255.0   U         0 0          0 vmnet8
192.168.122.0   0.0.0.0         255.255.255.0   U         0 0          0 virbr0

这是 Windows 上的路由表:

$ netstat -ar
===========================================================================
Interface List
 23...8c 16 45 26 ae 98 ......Intel(R) Ethernet Connection (5) I219-LM
 20...0a 00 27 00 00 14 ......VirtualBox Host-Only Ethernet Adapter
 19...02 00 4c 4f 4f 50 ......Npcap Loopback Adapter
  4...76 e5 f9 dd 66 34 ......Microsoft Wi-Fi Direct Virtual Adapter
  7...74 e5 f9 dd 66 35 ......Microsoft Wi-Fi Direct Virtual Adapter #2
 12...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1
  2...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8
 13...74 e5 f9 dd 66 34 ......Intel(R) Dual Band Wireless-AC 8265
 11...74 e5 f9 dd 66 38 ......Bluetooth Device (Personal Area Network)
  1...........................Software Loopback Interface 1
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0    10.134.52.196    10.134.52.220     50
      10.134.52.0    255.255.255.0         On-link     10.134.52.220    306
    10.134.52.220  255.255.255.255         On-link     10.134.52.220    306
    10.134.52.255  255.255.255.255         On-link     10.134.52.220    306
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    331
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    331
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    331
      169.254.0.0      255.255.0.0         On-link   169.254.245.126    281
  169.254.245.126  255.255.255.255         On-link   169.254.245.126    281
  169.254.255.255  255.255.255.255         On-link   169.254.245.126    281
     192.168.56.0    255.255.255.0         On-link      192.168.56.1    281
     192.168.56.1  255.255.255.255         On-link      192.168.56.1    281
   192.168.56.255  255.255.255.255         On-link      192.168.56.1    281
    192.168.146.0    255.255.255.0         On-link     192.168.146.1    291
    192.168.146.1  255.255.255.255         On-link     192.168.146.1    291
  192.168.146.255  255.255.255.255         On-link     192.168.146.1    291
    192.168.195.0    255.255.255.0         On-link     192.168.195.1    291
    192.168.195.1  255.255.255.255         On-link     192.168.195.1    291
  192.168.195.255  255.255.255.255         On-link     192.168.195.1    291
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
        224.0.0.0        240.0.0.0         On-link      192.168.56.1    281
        224.0.0.0        240.0.0.0         On-link     192.168.146.1    291
        224.0.0.0        240.0.0.0         On-link     192.168.195.1    291
        224.0.0.0        240.0.0.0         On-link   169.254.245.126    281
        224.0.0.0        240.0.0.0         On-link     10.134.52.220    306
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    331
  255.255.255.255  255.255.255.255         On-link      192.168.56.1    281
  255.255.255.255  255.255.255.255         On-link     192.168.146.1    291
  255.255.255.255  255.255.255.255         On-link     192.168.195.1    291
  255.255.255.255  255.255.255.255         On-link   169.254.245.126    281
  255.255.255.255  255.255.255.255         On-link     10.134.52.220    306
===========================================================================
Persistent Routes:
  None

IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
  1    331 ::1/128                  On-link
 20    281 fe80::/64                On-link
 12    291 fe80::/64                On-link
  2    291 fe80::/64                On-link
 19    281 fe80::/64                On-link
 13    306 fe80::/64                On-link
 19    281 fe80::927:546c:aa9d:f57e/128
                                    On-link
  2    291 fe80::9ed:bfc8:373c:3ce6/128
                                    On-link
 12    291 fe80::a941:328d:af54:6a14/128
                                    On-link
 20    281 fe80::d8fb:7a9d:b018:8399/128
                                    On-link
 13    306 fe80::fcfd:d9cc:e5ba:3c31/128
                                    On-link
  1    331 ff00::/8                 On-link
 20    281 ff00::/8                 On-link
 12    291 ff00::/8                 On-link
  2    291 ff00::/8                 On-link
 19    281 ff00::/8                 On-link
 13    306 ff00::/8                 On-link
===========================================================================
Persistent Routes:
  None

我需要什么路由命令才能让 Ubuntu 访问 Windows 机器?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...