Why linux route config failed with two NIC in redundancy (Primary/secondary)? - linux

I've two nic (eth0/eth1) sending data to a router.
Only one is sending data at a time. I also need a static conf that doesn't change regarding if the NIC are up/down.
If I down eth0, I expect eth1 to make the job.
But destroying eth0 destroy also my default route to the router. So I'm done.
Adding 2 default route seem to work by hand, but I don't want this solution.
So I've tried to add "full" route for eth0 and eth1?
By hand it work but I failed to add them in route-eth0 and route-eth1.
$cat route-eth0
178.12.34.240 via 10.0.10.1 dev eth0
$cat route-eth1
178.12.34.240 via 10.0.10.1 dev eth1
$service network restart
...
Bringing up interface eth1:
Determining IP information for eth1... done.
RTNETLINK answers: File exists
...
$route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
178.12.34.240 10.00.10.1 255.255.255.255 UGH 0 0 0 eth0
...
As you can see route for eth1 failed to be applied. For sure because of the File exist error.
Question:
What is the conf to set to always have correct route whatever the NIC are up or down.
Or another best practice ? What about VIP?

Yes, Ron metric is the answer. But I did it on a static route.
It seems having several default route should be banned.
$cat route-eth0
178.12.34.240 via 10.0.10.1 metric 1 dev eth0
$cat route-eth1
178.12.34.240 via 10.0.10.1 metric 2 dev eth1

Related

Name resolution for dummy interfaces

I've a virtual NIC of type NAT on my Ubuntu 20.04 virtual machine which connects it to the internet via host. For some processing, I need to route all incoming and outgoing packets via a program I've to write. For example, assume that I've to drop some packets and don't let them go out of the VM.
For this, I created a dummy interface with the following:
modprobe dummy
ip link add tun0 type dummy
ifconfig tun0 up
For all traffics not to go directly through the NIC, I added:
ip route add default dev tun0
Now everything is ok. For example when I
ping 4.2.2.4
, I see that the ping is not answered when my program is not running and is answered properly when it's running. The program works like a bridge between enp0s3 and tun0 for now. The whole traffic is routing through my program. Just a problem exists, name resolution. That's when I
ping google.com
, the name can't be resolved. The route table now is as follows:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 tun0
0.0.0.0 10.0.2.2 0.0.0.0 UG 20100 0 0 enp0s3
10.0.2.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s3
Of couse if I
sudo route del default
, the name resolution takes place via the NAT adapter through the host properly. Please let me know what's wrong with the name resolution in this situation.

Access internet with second (or multiple) NIC in Azure

I have a VM in Azure with Ubuntu 19.04 and 4 NICs, each one has a public IP attached to it, as an example, this is the second NIC:
As you can see, it has public IP 191.234.186.19.
My objective is to be able to access the internet from each NIC with a different IP address, but inside the VM I'm only able to access it with the first network eth0.
Looking at # route -n I get this output:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.1 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth3
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
168.63.129.16 10.0.0.1 255.255.255.255 UGH 100 0 0 eth0
169.254.169.254 10.0.0.1 255.255.255.255 UGH 100 0 0 eth0
I tried to add routes for the other NICs with the following commands:
sudo ip route add default via 10.0.0.1 dev eth1 metric 101
sudo ip route add default via 10.0.0.1 dev eth2 metric 102
sudo ip route add default via 10.0.0.1 dev eth3 metric 103
But again I still can't connect to the internet with these NICs, only eth0.
Am I missing something? Should I need to change/configure anything else to make this work?
For completeness, I'm using this command to test the connectivity:
curl --interface eth1 api.ipify.org?format=json -w "\n"
And my VM is the same as the one in this article: article
I suspect you might need to
1) define new routing tables for your 2nd, 3rd and 4th interface,
2) add default routes to those tables
3) and define rules to ensure return packets always get routed back into the same interface the originating packets were sent from.
There are a few examples out there for your reference (for example this and this).
I'll just point out a couple of points that you might find helpful when setting this up for your specific case:
iproute allows you to maintain multiple routeing tables. To instruct the OS to utilise different routing tables you need to define rules that in most simplistic form will enforce the use of routing table corresponding to the interface that initiated the connection.
It looks like only eth0 has a default gateway. You cannot comunicate outside the local network without a default gateway

how to save ip rule and ip route configuration

The issus is:
I configured the following policy routing:
ip route add 192.168.1.0/24 via 10.0.2.15 dev eth0 table 10
ip route add default via 10.0.2.15 dev eth0 table 10
ip rule add from 10.0.2.15 table 10
these configurations are temporary, once network restart or reboot,the policy route I configured would lost, Is there any way you can solve this problem?
Create a file if does not exist
/etc/sysconfig/network-scripts/route-eth0
Add the following contents
192.168.1.0/24 via 10.0.2.15 dev eth0
default via 10.0.2.15 dev eth0
default route can be added in /etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY=10.0.2.15
Third rule is not clear to me

manually set gateway using static routing

For study purpose I want to setup the following networking
A:
10.130.247.92/16(private on eth1)
128.199.227.240(public on eth0)
B:
10.130.237.218/16(private on eth1)
128.199.211.182/18(public on eth0)
And use B as gateway for private route.
in A
root#privte2:~# ip route list
default via 128.199.192.1 dev eth0
10.130.0.0/16 dev eth1 scope link
128.199.192.0/18 dev eth0 scope link
and
root#privte2:~# ip route add 10.130.0.0/16 via 10.130.247.92 dev eth1
RTNETLINK answers: File exists
Can anyone tell me where i did wrong?
I tried something like this before. See if this can help you. First enable the ipforwarding in both the machines.
locate the line containing net.ipv4.ip_forward in the /etc/syscl.conf file and make the following change.
net.ipv4.ip_forward=1
May be you need to restart for this.
Not really sure, Try this route command and see if it works.
Machine>$ route add -net 10.130.0.0 netmask 255.255.255.0 gw 128.199.211.182
For instance see here.

Cannot ping default gateway linux in vmware

I have a virtual network which is vmnet2 using the 10.0.2.0/24 network, I want my Linux server to be able to ping the default gateway.
I have set the Linux eth1 values to be
IPADDR="10.0.2.50"
NETMASK="255.255.255.0"
BOOTPROTO="none"
ONBOOT="yes"
In the etc/sysconfig/network
GATEWAY="10.0.2.1"
However, when I attempt to ping 10.0.2.1 the destination host is unreachable. I've restarted the network with service network restart but to no avail.
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.2.0 255.255.255.0 U 1 0 0 eth1
default 10.0.2.1 0.0.0.0 UG 0 0 eth1
The first row is the ipaddress and the second is the default gateway
Please make sure below,
Bridge the connection from your desktop .
You should be able to ping your Virtual machine IP from the parent machine where you have hosted the same.
Make sure you should not have any iptables rules configured that are constraing your connectivity.
This seems to enough , i have made similar setup recently.
Thanks,
Jain
You should add DEFROUTE=no in your eth1 configuration.

Resources