PC上测试

Ubuntu 16.04 本身已经支持双网卡同时工作,使用route命令查看时可以看到,目前无线网卡有线网卡已经同时在工作,其中wlp2s0无线网卡enxa44cc8f621d9有线网卡

tony@pc:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         localhost       0.0.0.0         UG    100    0        0 enxa44cc8f621d9
default         localhost       0.0.0.0         UG    600    0        0 wlp2s0
link-local      *               255.255.0.0     U     1000   0        0 wlp2s0
172.16.1.0      *               255.255.255.0   U     0      0        0 vmnet1
192.168.1.0     *               255.255.255.0   U     100    0        0 enxa44cc8f621d9
192.168.43.0    *               255.255.255.0   U     600    0        0 wlp2s0
192.168.212.0   *               255.255.255.0   U     0      0        0 vmnet8
tony@pc:~$ 

前两个default默认网关,实际连接的话,有线网卡网卡能上外网,无线网卡只是一个局域内网。由于有这一行,系统在能正常通过有线网卡访问外网的同时,也可以通过无线网卡访问192.168.43.0号段的局域内网。

192.168.43.0    *               255.255.255.0   U     600    0        0 wlp2s0

做一个测试,其中baidu.com是外网,可以如下正常ping通。


tony@pc:~$ ping baidu.com
PING baidu.com (111.13.101.208) 56(84) bytes of data.
64 bytes from 111.13.101.208: icmp_seq=1 ttl=52 time=4.23 ms
64 bytes from 111.13.101.208: icmp_seq=2 ttl=52 time=3.75 ms
64 bytes from 111.13.101.208: icmp_seq=3 ttl=52 time=3.80 ms
64 bytes from 111.13.101.208: icmp_seq=4 ttl=52 time=4.38 ms
^C
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 3.750/4.044/4.382/0.281 ms

其中192.168.43.37是局域内网下的一个设备,同样可以ping通,如下。

tony@pc:~$ ping 192.168.43.37
PING 192.168.43.37 (192.168.43.37) 56(84) bytes of data.
64 bytes from 192.168.43.37: icmp_seq=1 ttl=64 time=468 ms
64 bytes from 192.168.43.37: icmp_seq=2 ttl=64 time=80.8 ms
64 bytes from 192.168.43.37: icmp_seq=3 ttl=64 time=204 ms
64 bytes from 192.168.43.37: icmp_seq=4 ttl=64 time=25.3 ms
64 bytes from 192.168.43.37: icmp_seq=5 ttl=64 time=45.0 ms
64 bytes from 192.168.43.37: icmp_seq=6 ttl=64 time=67.8 ms
^C
--- 192.168.43.37 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5007ms
rtt min/avg/max/mdev = 25.310/148.657/468.156/153.996 ms
tony@pc:~$ 

NanoPC-T2 Linux 上测试

连接上WiFi和以太网后,route就自动配置好了,如下所示,且ping外网和内网时可同时使用。

pi@FriendlyELEC:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr ca:ef:1f:c4:4e:ce  
          inet addr:192.168.1.124  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::8e3b:4240:cd32:eea6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2281 errors:0 dropped:0 overruns:0 frame:0
          TX packets:781 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:462086 (462.0 KB)  TX bytes:70968 (70.9 KB)
          Interrupt:64 Base address:0x4000 

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:1297 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1297 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:109194 (109.1 KB)  TX bytes:109194 (109.1 KB)

wlan0     Link encap:Ethernet  HWaddr b0:f1:ec:29:06:18  
          inet addr:192.168.43.53  Bcast:192.168.43.255  Mask:255.255.255.0
          inet6 addr: fe80::20ff:6245:96eb:1993/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:112 errors:0 dropped:1264 overruns:0 frame:0
          TX packets:522 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:18279 (18.2 KB)  TX bytes:90094 (90.0 KB)

pi@FriendlyELEC:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         localhost       0.0.0.0         UG    100    0        0 eth0
default         localhost       0.0.0.0         UG    600    0        0 wlan0
192.168.1.0     *               255.255.255.0   U     100    0        0 eth0
192.168.43.0    *               255.255.255.0   U     600    0        0 wlan0
pi@FriendlyELEC:~$ ping 192.168.43.85
PING 192.168.43.85 (192.168.43.85) 56(84) bytes of data.
64 bytes from 192.168.43.85: icmp_seq=1 ttl=64 time=87.4 ms
64 bytes from 192.168.43.85: icmp_seq=2 ttl=64 time=105 ms
64 bytes from 192.168.43.85: icmp_seq=3 ttl=64 time=27.0 ms
64 bytes from 192.168.43.85: icmp_seq=4 ttl=64 time=49.7 ms
64 bytes from 192.168.43.85: icmp_seq=5 ttl=64 time=95.5 ms
64 bytes from 192.168.43.85: icmp_seq=6 ttl=64 time=96.0 ms
64 bytes from 192.168.43.85: icmp_seq=7 ttl=64 time=17.3 ms
^C
--- 192.168.43.85 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6003ms
rtt min/avg/max/mdev = 17.389/68.420/105.762/33.631 ms
pi@FriendlyELEC:~$ ^C
pi@FriendlyELEC:~$ 
pi@FriendlyELEC:~$ 
pi@FriendlyELEC:~$ ping 202.108.22.5
PING 202.108.22.5 (202.108.22.5) 56(84) bytes of data.
64 bytes from 202.108.22.5: icmp_seq=1 ttl=57 time=2.22 ms
64 bytes from 202.108.22.5: icmp_seq=2 ttl=57 time=1.97 ms
64 bytes from 202.108.22.5: icmp_seq=3 ttl=57 time=1.85 ms
64 bytes from 202.108.22.5: icmp_seq=4 ttl=57 time=2.29 ms
^C
--- 202.108.22.5 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 1.856/2.086/2.296/0.182 ms
pi@FriendlyELEC:~$ 
  1. localhost是什么意思?
    使用busybox route查看,不再是localhost了,这个应该更准确一点,更清晰了,这样设置就对了。
pi@FriendlyELEC:~$ busybox route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    100    0        0 eth0
default         192.168.43.1    0.0.0.0         UG    600    0        0 wlan0
192.168.1.0     *               255.255.255.0   U     100    0        0 eth0
192.168.43.0    *               255.255.255.0   U     600    0        0 wlan0
pi@FriendlyELEC:~$ 
  1. https://zhidao.baidu.com/question/43482647.html
    https://zhidao.baidu.com/question/256198410.html
    https://blog.csdn.net/an_zhenwei/article/details/37883843
    https://blog.csdn.net/hshl1214/article/details/53103790

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐