Score:0

Routing Table Metric With Two Interfaces

lt flag

I've tried for many hours now to find a solution to my issue, but I can't seem to locate a permanent explanation - I'm also an ultra noob, so forgive me if I get the basics incorrect.

I have a server running on LTS Ubuntu 22.04 with two interfaces, eno1 and eno2 - one interface has an internet connection (eno1) which I would like to have priority over the interface without an internet connection (eno2). I have this setup because I'd like to transfer files between LAN over eno2 while utilising the eno1 network.

The issue I'm having is that when booting up the server or establishing a connection to eno2, a route entry is automatically generated giving the eno2 interface a metric of 0; which from what I've researched means that my network traffic will utilise that interface over others - which in turn, disables me from using the internet.

This is a server installation of Ubuntu, I'm looking for both interfaces to be on separate subnets as the PC connected to the server through LAN has a separate interface for an internet connection.

I don't need the hosts connected to eno2 to be able to have internet access, just for eno1 to be the default connection for the server.

What I've tried -

  • Doing the command: sudo ip route del 192.168.0.0/24 dev eno 2 proto kernel scope link src 192.168.0.88 solves the issue, however, this is not permanent as when the system reboots or a connection is established through the interface it just recreates the route with a metric of 0.
  • I've tried adding an identical route entry into /etc/netplan/00-installer-config.yaml but that just creates a new entry with a different metric.
  • I've tried creating a script that will automatically delete the route when the system starts - but, this route is added back when a connection is made to the server's eno2 interface.

ip route:

default        via 192.168.0.1 dev   eno1   proto dhcp src 192.168.0.2  metric 100
192.168.0.0/24 dev eno2        proto kernel scope link src 192.168.0.88
192.168.0.0/24 dev eno1        proto kernel scope link src 192.168.0.2  metric 100
192.168.0.1    dev eno1        proto dhcp   scope link src 192.168.0.2  metric 100
194.168.4.100  via 192.168.0.1 dev   eno1   proto dhcp src 192.168.0.2  metric 100
194.168.8.100  via 192.168.0.1 dev   eno1   proto dhcp src 192.168.0.2  metric 100

route -n:

Destination     Gateway       Genmask           Flags Metric Ref Use Iface
0.0.0.0         192.168.0.1   0.0.0.0           UG    100    0   0   eno1
192.168.0.0     0.0.0.0       255.255.255.0     U     0      0   0   eno2
192.168.0.0     0.0.0.0       255.255.255.0     U     100    0   0   eno1
192.168.0.1     0.0.0.0       255.255.255.255   UH    100    0   0   eno1
192.168.4.100   192.168.0.1   255.255.255.255   UGH   100    0   0   eno1
192.168.8.100   192.168.0.1   255.255.255.255   UGH   100    0   0   eno1

/etc/netplan/00-installer-config.yaml:

network:
  ethernets:
    eno1:
      dhcp4: true
    eno2:
      dhcp4: false
      addresses: [192.168.0.88/24]
  version: 2

ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdic noqueue state UNKNOWN group default qlen 1000
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
   inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
   inet ::1/128 scope host
        valid_lft forever preferred_lft forever
2: eno1: <BROADCAST.MULTICAST.UP.LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
   link/ether (MAC) brd ff:ff:ff:ff:ff:ff
   altname enp3s0f0
   inet 192.168.0.2/24 metric 100 brd 192.168.0.255 scope global dynamic eno1
        valid_lft 86395sec preferred_lft 86395sec
   inet6 fe80::2fd:35ff:fefc:5648/64 scope link
        valid_lft forever preferred_lft forever
3: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
   link/ether (MAC) brd ff:ff:ff:ff:ff:ff
   altname emp3s0f1
   inet 192.168.0.88/24 brd 192.168.0.255 scope global eno2
        valid_lft forever preferred_lft forever
   inet6 fe80::2fd:45ff:fefc:5649/64 scope link
        valid_lft forever preferred_lft forever

If there's anything you can help with, I'd be much appreciative. Also, if there's further information you need, I'll gladly oblige.

Thank you.

mpboden avatar
do flag
What is the output of `ip a`? Is this a desktop or server installation of Ubuntu? Are you intending both interfaces to be on the same subnet? If so, do you want LAN traffic to go over `eno2` yet default traffic over `eno1`? Do you want hosts connected to `eno2` to be able to access internet through this host via `eno1`? Please update question with this information.
Wilson avatar
lt flag
Hey, @mpboden - thank you for the reply. The output of ip a is: [link](https://i.imgur.com/td8gLj1.png) I blurred out what I think are the MAC addresses of the interfaces. This is a server installation of Ubuntu - I'd like for the interfaces to be on separate subnets as eno2 is directly connected to my home PC and eno1 is connected to the router. I don't want hosts to be able to access the internet through eno2. Thank you <3
mpboden avatar
do flag
Please update the original question with this new information. Also, copy/paste the output of `ip a` instead of linking a picture.
Wilson avatar
lt flag
@mpboden I've updated the original question with the new information, ILO doesn't let me paste from the interface so I've typed it out to the best of my abilities.
Score:1
lt flag

After some soul searching and furious trial and error I found the solution to my problem - which @mpboden may have contributed towards.

When setting the default route towards the router in netplan - I needed to add the nameservers for the internet to function.

The netplan that worked:

network:
  ethernets:
    eno1:
      dhcp4:false
      addresses: [192.168.0.2/24]
      routes:
        - to: default
          via: 192.168.0.1
          metric: 0
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]
    eno2:
      dhcp4: false
      addresses: [192.168.1.88/24]
  version: 2

after saving the file, do netplan apply to apply the netplans changes.

mpboden avatar
do flag
Glad you got it to work. Setting up both interfaces with static IPs is a perfect solution. However, I’m curious as to why setting up `eno1` as DHCP didn’t work. Your DHCP server should be sending you DNS servers if configured to do so. Anyway, I’ll have to do some testing later for my own. Perhaps the default route still needed to be defined on `eno1`.
Wilson avatar
lt flag
Thanks for all your help @mpboden yeah, I'm not entirely sure exactly why it needed to be defined on eno1 - The DHCP server is all default settings from my ISP.
mpboden avatar
do flag
After testing, I have a server w/ DHCP on `eno1` and a static IP on different subnet on `eno2`. Default route is `eno1` with metric of 100. `eno2` has a metric of 0. With this setup, there are no problems. The lower metric of `eno2` doesn't affect the default route, because there's only one default route set on `eno1`. If you had two default routes, on `eno1` and `eno2`, then the one w/ lower metric would win. So w/ the setup I suggested in my answer, it should work. But since it's not, I'm wondering if DNS servers weren't being sent to you. You could explore this more if desired.
Score:0
do flag

You’ve stated that you want both eno1 and eno2 on separate subnets, but they’re actually on the same subnet: 192.168.0.0/24. So this appears to be your problem.

My suggestion then is to update your Netplan YAML file so that eno2 is on a different subnet. Of course, this would mean all hosts behind eno2 would need to be configured to be in this subnet as well.

If you want to be able to allow traffic to be forward between eno1 and eno2, then you need to enable IP forwarding.

To check if IP forwarding is enabled or not, use sysctl:

$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

In this example, net.ipv4.ip_forward is set to 0. That means it’s off. If it were set to 1, that would mean it’s enabled.

To enable, use the following command:

sysctl -w net.ipv4.ip_forward=1

Or…

echo 1 > /proc/sys/net/ipv4/ip_forward

To make the change persistent, edit /etc/sysctl.conf and add the following:

net.ipv4.ip_forward = 1

Then either reboot the system or run sysctl -p to load the new settings from /etc/sysctl.conf.

Finally, if you have a firewall configured on the system, then you may need to update that to allow traffic as well.

Wilson avatar
lt flag
Hello, I changed the subnet of eno2 in netplan so it displays the ip as 192.168.1.88 with a subnet of 192.168.1.255 - I've also manually set eno1 to have a default gateway, which is my router's address - 192.168.0.1, doing sysctl net.ipv4.ip_forward displays it already being enabled, it's set to 1. However, there is still no internet connectivity on the server; I'm unable to do an apt update or any functions that require internet connectivity. Note: route -n now displays the metrics of both interfaces as 0.
I sit in a Tesla and translated this thread with Ai:

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.