Score:0

Ubuntu 20.04 Server: 2 networks, 2 gateways and static routes

kh flag

I need to add a second network with a second gateway to my ubnutu 20.04 server (with netplan). The setting looks like this:

Ubuntu server:

interface: ens18
IP: 192.168.20.2
gateway: 192.168.20.1
netmask: 255.255.255.0

I need to add a second network (192.168.30.2/24) with a second router (192.168.30.1) as gateway to the server. This router has different vpn connections to external networks.

I also need to ad static routes to ubuntu server in order to use the vpn connections of the second router, something like:

route XXX.YYY.0.0 MASK 255.255.0.0 via gateway 192.168.30.1
route XXX.ZZZ.0.0 MASK 255.255.0.0 via gateway 192.168.30.1
route XXX.XXX.0.0 MASK 255.255.0.0 via gateway 192.168.30.1
route WWW.XYZ.0.0 MASK 255.254.0.0 via gateway 192.168.30.1
route QQQ.PPP.RRR.0 MASK 255.255.255.0 via gateway 192.168.30.1

In windows I add the static routes with:

route add XXX.YYY.0.0 MASK 255.255.0.0 192.168.30.1 -p
...

My curent netplan YAML is:

# This is the network config written by 'subiquity'
network:
  ethernets:
    ens18:
        addresses: [192.168.20.2/24]
        dhcp4: no
        gateway4: 192.168.20.1
        nameservers:
            addresses: [192.168.20.1, 8.8.8.8]
  version: 2
 # renderer: networkd
 # renderer: NetworkManager

How can I realise this network?

ru flag
Normally you'd do this with a second network interface, is there a reason you have to do this all on the same single network interface?
DevOpt avatar
kh flag
No, there is no reason to do this on the same network interface. How would the solution looks like with two interfaces?
ru flag
well, typically, ther'es only one gateway on the computer that's the primary. Why do you need two gateways? It's relevant so that we can make sure your computer still works properly for the 'default' route (to Internet)
DevOpt avatar
kh flag
In this case the second gateway is relevant for the vpn connections. The second router is configured in a seperate network and is the gateway for this network, it was done this way for security reasons (network separation).
ru flag
By gateway, I mean gateway to the Internet. Not gateway to other network resources. It's trivial to set up routes so certain resources go via the second connection, while others go via the main connection. That's what the 'gateway' address is for - defining the default routes to the Internet. Is your intention to *only* send certain data over one connection and the rest over the other, or are you looking for some special routing rules at play here? (you can only have one 'default' gateway on a system, you can set up routing rules if you need certain traffic over certain conns, and not others)
DevOpt avatar
kh flag
The intention is to send (and receive) some data via the second router (192.168.30.1) to the VPN destinations. The result should be the same as to add a new network and static routes on a Windows system.
Score:0
kh flag

In this case the YAML file could look like this:

# This is the network config written by 'subiquity'
network:
  version: 2
  renderer: networkd
  ethernets:
    ens18:
      addresses: [192.168.20.2/24, 192.168.30.2/24]
      dhcp4: no
      gateway4: 192.168.20.1
      nameservers:
        addresses: [192.168.20.1, 192.168.30.1]
        search: []
      routes:
       - to: ZZZ.ZZZ.0.0/15
         via: 192.168.30.1
       - to: XXX.XXX.0.0/16
         via: 192.168.30.1
       - to: XXX.VVV.0.0/16
         via: 192.168.30.1
       - to: XXX.HHH.0.0/16
         via: 192.168.30.1
       - to: YYY.OOO.220.0/24
         via: 192.168.30.1
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.