Issues:
Suppose you have 2 network cards and their own gateway. The challenge is that you can only have 1 default gateway. How do we work this out?
Solution:
Type the following command
$ ip route show
default via 192.168.1.254 dev eno0 proto static metric 104
192.168.2.0/24 via 192.168.2.254 dev eno1 proto static metric 103
10.10.1.0/24 via 192.168.2.254 dev eno1 proto static metric 103
That means the default route for traffic is via eno1. All traffic except 192.168.2.0 and 10.10.1.0 will pass through the second gateway. How do we do it?
Set Default Route for all traffic
To set all traffic through the default gateway, do the following
$ ip route add default via 192.168.1.254 dev eno0 proto static metric 104
Set Selected IP Subnet for 2nd Gateway
$ ip route add 192.168.2.0/24 via 192.168.2.254 dev eno1 proto static metric 103
$ ip route add 10.10.1.0/24 via 192.168.2.254 dev eno1 proto static metric 103
Setting the DNS Correctly for each Network Card
If each of the Network Cards requires a different DNS, do make sure you put in the /etc/sysconfig/network-scripts
$ vim /etc/sysconfig/network-scripts/ifcfg-eno0
....
....
DEVICE=eno0
ONBOOT=yes
IPADDR=192.168.1.1
GATEWAY=192.168.1.254
DNS1=192.168.1.252
DNS2=192.168.1.253
NETMASK=255.255.255.0
$ vim /etc/sysconfig/network-scripts/ifcfg-eno1
....
....
DEVICE=eno1
ONBOOT=yes
IPADDR=192.168.2.1
GATEWAY=192.168.2.254
DNS1=192.168.2.252
DNS2=192.168.2.253
NETMASK=255.255.255.0
Deleting Route from Table
ip route delete 192.168.2.0/24 via 192.168.2.254 dev eno1 proto static metric 103
Different DNS Servers and Different Domains (For RHEL 8)
You can configure dnsmasq service and NetworkManager to send DNS queries for a specific domain to a selected DNS server. The Information can be found in Chapter 38. Using different DNS servers for different domains
By default, Red Hat Enterprise Linux (RHEL) sends all DNS requests to the first DNS server specified in the /etc/resolv.conf file. If this server does not reply, RHEL uses the next server in this file.
In environments where one DNS server cannot resolve all domains, administrators can configure RHEL to send DNS requests for a specific domain to a selected DNS server. For example, you can configure one DNS server to resolve queries for example.com
and another DNS server to resolve queries for example.net
. For all other DNS requests, RHEL uses the DNS server configured in the connection with the default gateway.
Procedure 1: Install dnsmasq package
# dnf install dnsmasq
Procedure 2: Edit the /etc/NetworkManager/NetworkManager.conf file, and set the following entry in the [main] section:
dns=dnsmasq
Procedure 3: Reload the NetworkManager service:
# systemctl reload NetworkManager
Procedure 4: Verify that the nameserver entry in the /etc/resolv.conf file refers to 127.0.0.53:
# cat /etc/resolv.conf
nameserver 127.0.0.1
Procedure 5a: Verify using TCPDump Packet Sniffer
# dnf install tcpdump
Procedure 5b: On one terminal, start tcpdump to capture DNS traffic on all interfaces:
# tcpdump -i any port 53
Procedure 5c: On a different terminal, resolve host names for a domain for which an exception exists and another domain, for example:
# host -t A www.redhat.com
# host -t A www.MyInternalDomain.com
Verify in the tcpdump output that Rocky Linux sends only DNS queries for the http://www.redhat.com domain to the designated DNS server and through the corresponding interface and vice versa for the Internal Domain
References:
- Chapter 38. Using different DNS servers for different domains
- Two Default Gateways on One System
- Linux Set up Routing with IP Command