Contents
  1. 1. Configuring DNS
  2. 2. Configuring Default Route Gateway
    1. 2.1. Get Default Gateway IP
    2. 2.2. Check the Route Table
    3. 2.3. Update the 0.0.0.0 Route to the Default Gateway
      1. 2.3.1. ip command
      2. 2.3.2. route command
      3. 2.3.3. Update configuration file
  3. 3. Restart Networking
  4. 4. Appendixes
  5. 5. References

Configuring DNS

Ensure your Linux server’s DNS configuration file /etc/resolv.conf contains some DNS servers.

If there are no DNS servers in the /etc/resolv.conf, you must add some DNS servers to the file.

1
vim /etc/resolv.conf

Add the following content to the file /etc/resolv.conf

1
2
3
nameserver 192.168.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4

You can try to restart your system networking to check whether the problem of being unable to ping domain names is resolved. See the section “Restart Networking” of this post.

Configuring Default Route Gateway

You need to check your route table and check if the destination host 0.0.0.0 is routed to the default gateway IP (e.g. 192.168.0.1). If not you need to update the gateway IP.

Get Default Gateway IP

1
$ ip r | grep default
1
default via 192.168.0.1 dev eth0 proto dhcp metric 100

Some computers might have multiple default gateways. The gateway with lowest Metric is the first to be searched and used as the default gateway.

My server’s default gateway IP is 192.168.0.1.

Check the Route Table

Print the route table:

1
$ sudo route -n
1
2
3
4
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
...
  • Destination: The destination network or destination host.
  • Gateway: The gateway address or ’*’ if none set.
  • Genmask: The netmask for the destination net: 255.255.255.255 for a host destination and 0.0.0.0 for the default route.

What Is The Meaning of 0.0.0.0 In Routing Table?

Each network host has a default route for each network card. This will create a 0.0.0.0 route for such card. The address 0.0.0.0 generally means “any address”. If a packet destination doesn’t match an individual address in the table, it must match a 0.0.0.0 gateway address. In other words, default gateway is always pointed by 0.0.0.0

Update the 0.0.0.0 Route to the Default Gateway

Update the destination host 0.0.0.0 route the the default gateway IP e.g 192.168.0.1.

ip command

You can temporarily update the 0.0.0.0 route gateway by the ip command.

Add the default route:

1
ip route add default via 192.168.0.1

You can also delete the default route:

1
ip route delete default

route command

You can temporarily update the 0.0.0.0 route gateway by the route command.

Add the default route:

1
route add default gw 192.168.0.1

You can also delete the default route:

1
route del default gw 192.168.0.1

Update configuration file

You can permanently update the 0.0.0.0 route gateway by in system configuration file.

CentOS/RHEL

1
vim /etc/sysconfig/network

Add the following content to the file /etc/sysconfig/network

1
2
NETWORKING=yes
GATEWAY=192.168.0.1

Debian/Ubuntu

1
vim /etc/network/interfaces

Find network interface and add the following option

1
2
3
... 
gateway 192.168.0.1
...

Restart Networking

After update the gateway configuration file, you need restart the networking.

Restart the networking on CentOS/RHEL

1
2
3
4
sudo systemctl restart NetworkManager.service
# or
sudo systemctl stop NetworkManager.service
sudo systemctl start NetworkManager.service

Restart the networking on Debian/Ubuntu

1
sudo /etc/init.d/networking restart

Appendixes

Some public DNS servers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# OpenDNS
208.67.222.222
208.67.220.220

# Cloudflare
1.1.1.1
1.0.0.1

# Google
8.8.8.8
8.8.4.4

# Quad9
9.9.9.9

References

[1] Understanding Routing Table

[2] What Is The Meaning of 0.0.0.0 In Routing Table?

Contents
  1. 1. Configuring DNS
  2. 2. Configuring Default Route Gateway
    1. 2.1. Get Default Gateway IP
    2. 2.2. Check the Route Table
    3. 2.3. Update the 0.0.0.0 Route to the Default Gateway
      1. 2.3.1. ip command
      2. 2.3.2. route command
      3. 2.3.3. Update configuration file
  3. 3. Restart Networking
  4. 4. Appendixes
  5. 5. References