Wednesday, August 2, 2017

[Raspberry Pi] Use Wireless and Ethernet together

The following content is my Raspberry Pi 3's setting in /etc/network/interface as follows. In my case, I both use wireless and ethernet device at the same time.
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
    Wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug eth0
iface eth0 inet static
    address 140.96.29.224
    netmask 255.255.255.0
    up ip route add 100.85.0.0/24 via 140.96.29.254 dev eth0
    up ip route add 140.96.29.0/24 via 140.96.29.254 dev eth0
    up ip route add 140.96.98.0/24 via 140.96.29.254 dev eth0



But, this situation will encounter routing problem like this ( There are two default gateways):
I only want the 2nd one.
pi@raspberrypi:~ $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         140.96.29.254   0.0.0.0         UG    202    0        0 eth0
default         10.99.0.254     0.0.0.0         UG    303    0        0 wlan0
10.99.0.0       *               255.255.0.0     U     303    0        0 wlan0
100.85.0.0      140.96.29.254   255.255.255.0   UG    0      0        0 eth0
140.96.29.0     *               255.255.255.0   U     202    0        0 eth0

I currently just delete the first default route manually:
pi@raspberrypi:~ $ sudo route del default
pi@raspberrypi:~ $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.99.0.254     0.0.0.0         UG    303    0        0 wlan0
10.99.0.0       *               255.255.0.0     U     303    0        0 wlan0
100.85.0.0      140.96.29.254   255.255.255.0   UG    0      0        0 eth0
140.96.29.0     *               255.255.255.0   U     202    0        0 eth0

If you have a better resolution approach, please let me know that. Thanks.


No comments: