Setting default gateway on CentOS 7 and showing it using route and netstat -r

16,008

Try running netstat -nr as opposed to netstat -r. Same for route, run route -n instead. This will show the actual IP address instead of the hostname.

Share:
16,008

Related videos on Youtube

Alex
Author by

Alex

Updated on September 18, 2022

Comments

  • Alex
    Alex almost 2 years

    I am following a tutorial found here on how to setup a gateway for each adapter and also a default gateway:

    http://linux-training.be/sysadmin/ch22.html

    But when I run the commands

    $ route
    

    and

    $ netstat -r
    

    the gateway does not appear as shown in the tutorial.

    Here are my relevant files:

    $ cat /etc/sysconfig/network
    
    NETWORKING=yes
    HOSTNAME=lvs
    GATEWAY=192.168.1.1
    
    
    $ cat /etc/sysconfig/network-scripts/ifcfg-eth0
    
    NAME=eth0
    DEVICE=eth0
    TYPE=Ethernet
    NM_CONTROLLED=no
    BOOTPROTO=none
    ONBOOT=yes
    
    HWADDR=08:00:27:47:BD:B3
    
    IPADDR0=192.168.1.100
    GATEWAY=192.168.1.1
    NETMASK=255.255.255.0
    
    
    $ cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
    
    TYPE=Ethernet
    BOOTPROTO=dhcp
    DEFROUTE=yes
    PEERDNS=yes
    PEERROUTES=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_PEERDNS=yes
    IPV6_PEERROUTES=yes
    IPV6_FAILURE_FATAL=no
    NAME=enp0s3
    UUID=5cc476e7-c116-41f0-bcb6-129fdba369ba
    DEVICE=enp0s3
    ONBOOT=yes
    

    I think I have followed everything correctly. So I don't understand why gateways does not show up as in the tutorial.

    $ route
    
    [root@lvs network-scripts]# route
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    default         gateway         0.0.0.0         UG    0      0        0 eth0
    link-local      0.0.0.0         255.255.0.0     U     1002   0        0 eth0
    192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
    
    $ netstat -r
    
    [root@lvs network-scripts]# netstat -r
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
    default         gateway         0.0.0.0         UG        0 0          0 eth0
    link-local      0.0.0.0         255.255.0.0     U         0 0          0 eth0
    192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
    
    • Michael Hampton
      Michael Hampton about 8 years
      But they do show up!
    • Alex
      Alex about 8 years
      But it just says gateway on default. I don't understand.