Set up two IP addresses with one gateway?

23,985

OK, it is working, and for referencing here is how I did it, hopefully someone will find it useful.

I found the solution on the following sites:

1- Multiple interfaces on the same subnet 2- Two network interfaces and two IP addresses on the same subnet in Linux

And the website that i referenced in the question as well.

suppose I have two IP addresses: 7.7.7.4 & 7.7.7.5 on network 7.7.7.0 and they have a gateway 7.7.7.1

I enabled ARP filtering:

# sysctl -w net.ipv4.conf.all.arp_filter=1
# echo "net.ipv4.conf.all.arp_filter = 1" >> /etc/sysctl.conf

And the I configured /etc/network/interfaces as following:

    # The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
   address 7.7.7.4
   network 7.7.7.0
   netmask 255.255.255.0
   broadcast 7.7.7.255
   up ip route add 7.7.7.0/24 dev eth0 src 7.7.7.4 table eth0table
   up ip route add default via 7.7.7.1 dev eth0 table eth0table
   up ip rule add from 7.7.7.4 table eth0table
   up ip route add 7.7.7.0/24 dev eth0 src 7.7.7.4

auto eth1
iface eth1 inet static
   address 7.7.7.5
   network 7.7.7.0
   netmask 255.255.255.0
   broadcast 7.7.7.255
   up ip route add 7.7.7.0/24 dev eth1 src 7.7.7.5 table eth1table
   up ip route add default via 7.7.7.1 dev eth1 table eth1table
   up ip rule add from 7.7.7.5 table eth1table
   up ip route add default via 7.7.7.1 dev eth1
   up ip route add 7.7.7.0/24 dev eth1 src 7.7.7.5

And I added the following two lines to /etc/iproute2/rt_tables

10 eth0table
20 eth1table

I have Ubuntu 12.04 LTS server

Share:
23,985

Related videos on Youtube

Ahmed
Author by

Ahmed

Updated on September 18, 2022

Comments

  • Ahmed
    Ahmed almost 2 years

    I would like to ask if it is possible to set up two static IPs from same subnet through one gateway? and How if it is?

    What I am interested in is described here Routing for multiple uplinks/providers, but in my case I have two IP addresses from one provider, both are on same subnet and off course I have internet access on both.

    I have two NICs, but I don't mind to go with one if that makes it possible.

    Any thought is appreciated!

    • Ahmed
      Ahmed almost 11 years
      Yes it is fairly general question so far, but the system I have (and can have) is Ubuntu only(12.04 LTS, but I can upgrade or downgrade), so if some one asked me to do something or for more information e.g. a command output, then I can do it.