1

This question already has an answer here:

System:

Ubuntu 18.10

I have a linux Desktop running that is connected to two different networks:

  • WLAN adapter connects to the wifi network for:
    • internet access
    • connect to vpn with openconnect
  • LAN connects to a local router for:
    • communication with other local computers:
      • vnc server on the linux desktop for other clients
      • ssh connections

My problem is I don't know how to control which tasks automatically use which networks. If I log on to the wifi first, and then connect the hardwire second, the internet seems to work. If I do this in reverse it doesn't.

If I ssh in from another computer, I can pick the appropriate router and then starting vnc server from the client will force the correct choice of network adapter to use.

So one overarching question, is there a way to set up rules or configurations so that these different tasks are directed to the appropriate network adapter?

marked as duplicate by Rui F Ribeiro, Christopher, Thomas, Haxiel, peterph Mar 3 at 22:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Are you using DHCP in both networks? You might want to set up the DHCP settings the wifi/wired routers are providing. – peterph Mar 3 at 22:58
3

Yes.

Going to do some guessing here, but it sounds like either both of your network adapters are configured for DCHP or both have default gateways specified in their configurations.

A good rule of thumb is only have one default gateway at a time and add static routes as needed.

One Default Gateway

If you have two default gateways, one for each interface, then networking can get pretty flaky. You have several options depending on how you want the networking to function.

Here are some suggestions:

  1. I would recommend setting a static IP address with no default gateway on your wired interface.
  2. Let your wifi use DHCP and accept a default gateway from the dhcp server.

Static Routes As Needed

The changes above might fix most of your issues unless you are sshing to hosts via your wired ethernet that live on other subnets. If so, its time to setup static routes.

Here is an example:

ip route add 172.16.100.0/24 via 172.16.1.1 dev eth0

This command adds a new static route to the network 172.16.100.0/24 via the router 172.16.1.1 reached from the interface eth0. (Assumes that the router is reachable from your host, which it sounds like it is).

Add one of these for each external network you need to route to instead of having a default gateway specified.

Bonus: To check how the kernel would route traffic to a network, just ask ip as well.

ip route get 172.16.1.10

The response should include all you need to know to troubleshoot your routing setup.

Once you get this figured out and working you can roll it into your netplan config and make it permanent.

Not the answer you're looking for? Browse other questions tagged or ask your own question.