0

I have a ubuntu server with two network cards. The IP of eth0 is 192.168.2.178/24, and the IP of eth1 is 192.168.2.179/24. This is my config with netplan:

network:
  ethernets:
    eth0:
      addresses:
      - 192.168.2.178/24
      dhcp4: false
      gateway4: 192.168.2.1
      nameservers:
        addresses:
        - 192.168.2.1
      optional: true
    eth1:
      addresses:
      - 192.168.2.179/24
      dhcp4: false
      optional: true
  renderer: networkd
  version: 2

When I finished configuring the network, two rules appeared in the routing table.

Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

There will be a conflict when accessing other IPs in the 192.168.2.0/24 network segment. I hope to access 192.168.2.100 through the eth1 network card, and access other IPs through the eth0 network card. How to achieve this effect by configuring netplan and making it permanent.

I have tried manually setting up a route.

$ route del -net 192.168.2.0 netmask 255.255.255.0 dev eth1
$ route add -host 192.168.2.100 dev eth1

But when the ubuntu server restarts or unplugs the network cable, the routing table will be restored.

4
  • You should set route priorities.
    – FedKad
    Nov 14, 2023 at 6:28
  • Please help me, how to set route priorities?
    – cctomato
    Nov 14, 2023 at 7:15
  • I have no practical information, but askubuntu.com/questions/1008571 may help.
    – FedKad
    Nov 14, 2023 at 14:13
  • Thanks, but this doesn't solve my problem.
    – cctomato
    Nov 15, 2023 at 3:08

1 Answer 1

0

not sure about your use case, but maybe you can set the cards with different ip segmant like: 192.168.2.0 192.168.1.0

or maybe you can add a route with a higher netmask like 192.168.2.178 255.255.255.255

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .