Static IP address without a gateway

8,377

You do not need a gateway entry for any NIC that you don't want to use to reach a network not in its collision domain (192.168/16 in this case). You can just omit that line if you don't want a gateway for that NIC.

I'm not sure what will happen if you try to use loopback as a gateway, but I wouldn't expect it to be happy times.

Share:
8,377

Related videos on Youtube

111---
Author by

111---

Updated on September 18, 2022

Comments

  • 111---
    111--- over 1 year

    Simple setup here. I have a machine with multiple network interfaces, two for example - eth0 and eth1.

    eth0 has a static address and has a default gateway assigned. eth1 has a static address and will not have a gateway on that interface's network address range.

    The Question

    Do I need an entry in network configuration file (/etc/network/interfaces) for the gateway option on the interface that does not have a gateway on its network, eth1 in the above example?

    Additional Questions

    If I do something like:

    gateway 127.0.0.1
    

    Will this have adverse effects? Will this interface now have a way to reach a gateway or will using the loopback interface as a gateway have no effect (i.e. same as leaving the gateway option off entirely)?

    Example config for discussion

    /etc/network/interfaces

    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # Interface 1
    allow-hotplug eth0
    iface eth0 inet static
    address 10.1.10.200
    netmask 255.255.255.0
    gateway 10.1.10.1
    
    # Interface 2
    allow-hotplug eth1
    iface eth1 inet static
    address 192.168.100.1
    netmask 255.255.0.0
    gateway 127.0.0.1     # This is the line in question
    
  • zwets
    zwets over 8 years
    I haven't tested but I would guess that trying to set 127.0.0.1 as a gateway for 192.168.100.1 will not work because they are in disjoint networks: 127/8 vs 192.168/16.