2

I'm working on a project for school that uses an Ubuntu machine connected to a Raspberry Pi through Ethernet with no internet connection (none needed). I also need a wireless connection to a separate local network which I am doing with a USB wireless adapter. I have little experience with Ubuntu and am not fully aware of what settings were put in place prior to me working on the system.

Both the Wifi and Ethernet are static with different IPs. Both connections work fine, but only one or the other. I need to have a wireless connection because I'm trying to send commands from Android to Apache on Ubuntu locally.

karel
  • 13,706

2 Answers2

1

To explain the comment here a little more, basically what you need to do is

  • connect to both ethernet and wifi, you should now have 2 interfaces showing in ifconfig -a.

Let's assume the wifi IP is 192.168.0.11 and the ethernet is 10.1.1.45. Wifi gateway is 192.168.0.1 and the ethernet gateway is 10.1.1.1

  • now you need to setup the routing table to send some traffic via ethernet and the rest via wifi. Lets say traffic destined for a couple of ethernet internal subnets - all 10.0.0.0/8 addresses (and for some strange reason) 149.9.1.0/24 should go via ethernet and everything else can go to wifi

Disclaimer - I dont have an ubuntu vm handy to test, these are the commands I use on a Mac to do the same thing

$ route add 10.0.0.0/8 10.1.1.1
$ route add 149.9.1.0/24 10.1.1.1

netstat -rn will show the routing table:

$ netstat -rn
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.0.0.0        10.1.1.1        255.0.0.0       UG        0 0          0 eth1
149.9.1.0       10.1.1.1        255.255.255.0   UG        0 0          0 eth1
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 eth0
169.254.169.254 0.0.0.0         255.255.255.255 UH        0 0          0 eth0
192.168.0.1     0.0.0.0         255.255.0.0     U         0 0          0 eth0

you might need to muck around with the ordering of the interfaces to make it work. netstat and ip will be your friends here.

stringy05
  • 138
0

Although this question pertains to Ubuntu 16.04, I am using 20.04.1 and thought I would post a working solution that I use on a Raspberry Pi 4, with Ubuntu Server 64-bit. Therefore, I offer the netplan file without further explanation.

network:
  ethernets:
      eth0:
        addresses: [192.168.1.4/24]
        gateway4: 192.168.1.2
        nameservers:
            addresses:
            - 192.168.1.2              # private IP for ns1
#           - 192.168.1.4              # private IP for ns2 (work in progress)
#            search: [ <your domain> ] # DNS zone           (work in progress)
        dhcp4: no                      # static IP assignment
# version: 2 (not sure this is required)

wifis: wlan0: # use ls /sys/class/net to determine this value addresses: [10.0.2.2/24] gateway4: 10.0.2.1 nameservers: addresses: - 10.0.2.2 # local host is ns1 access-points: "<your SSID>": password: "<your password>" dhcp4: no #static IP assignment

Giacomo1968
  • 58,727
Dave C
  • 1