Question

Multiple public IP addresses (different ranges) and only 1 gateway

Asked by: Xyptilon2

I'm having some difficulties. I have a machine that listens to several IP addresses. (public IP addresses). Each IP address is from a different range. Although the subnet mask is in both cases 255.255.255.0. Can I serve both using 1 gateway (also public) address? If I use different gateways, connectivity is lost soon after using both IP addresses. I'm using Debian , Linux and /etc/network/interfaces

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-03-27 at 08:58:48ID24271560
Tags

gateway

,

network

,

debian

Topics

Miscellaneous Networking

,

Linux

Participating Experts
3
Points
500
Comments
22

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Subnet masking
    Hi all, I need help with subnet masking on win2k server. Before we start please don't direct me to unhelpful links. I'd prefer your own explanation. Let's say currently there are about 150 clients logging onto win2k running DHCP. Subnet mask is 255.255.255.0. In a few mo...
  2. Populate an IP Range in Excel after inputting Subnet Mask/…
    What I want to do is this: I have 2 fields in Excel.. B3: Default Gateway B4: Subnet Mask Then I have a range from A7 - A10,000 What I need to happen is, when someone enters the Default Gateway Address in cell B3 and the Subnet Mask in B4, I want the gateway address to ap...
  3. What is subnet mask?
    What is subnet mask?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: omarfaridPosted on 2009-03-27 at 09:19:31ID: 24002656

yes, you can serve both using one default gateway, while multiple gateways should work as well

 

by: Xyptilon2Posted on 2009-03-28 at 08:21:27ID: 24008806

It doesn't seem to work. Let me restate that both IP addresses are in a completely different range. Each range has a gateway, however if I configure both (on the same interface), network services effectively go down. They only listen to 1 IP address at a time.

 

by: UberpappaPosted on 2009-03-28 at 15:45:43ID: 24010624

I think you should configure routeback with ip route 2. If you simply configure two gateways, Linux will load balance between them. This means traffic entering either IP will exit through either of them again, not the one through which it entered.

I always use shorewall to accomplish this, so I'm not too sure about the exact commands, but the theory behind it is:

1) Install iproute2
2) Create two routing tables in /etc/iproute2/rt_tables
3) Add the default gateway for ip 1 to routing table 1
4) Add the default gateway for ip 2 to routing table 2
5) Configure an ip routing rule so that traffic entering though IP 1, looks at routing table 1, and the traffic entereing through IP 2 looks at routing table 2

That way traffic entering though the one IP will look at a different routing table and thus have a different default gateway than traffic entering though the second IP. In this way, if it enters through IP 1, it exits through IP 1 again, and the other way around.

Have a look at the Linux Advanced Routing and Traffic control howto, found here:

http://lartc.org/

for more detail on how to do this.

Hope this helps

 

by: UberpappaPosted on 2009-03-28 at 15:48:18ID: 24010635

 

by: hfraserPosted on 2009-03-30 at 06:10:16ID: 24018460

If your servers are configured to listen to all ip addresses on the host,  the multiple paths shouldn't matter. You can check it using "netstat -an | grep 80" replacing "80" for whatever port your app is listening to. If it's listening to a single IP address, you need to reconfigure your app.

if there's a gateway in the picture (hopefully it's a firewall), why are your servers dealing with the public IP addresses? It might be simpler to delegate this responsibilty to the gateway, and let the servers deal with single private IP addresses.

 

by: UberpappaPosted on 2009-03-30 at 06:57:53ID: 24018941

Not to be hard arsed about it, but to my knowledge: It does matter.

Lets say you have (excuse the fake ip addresses) ip1=1.1.1.1, gateway=1.1.1.2 and ip2=2.2.2.1, gateway=2.2.2.2.2.

If you simply add two gateways, 1.1.1.2 and 2.2.2.2, Linux will choose either to reply. If you connect to, say apache, on 1.1.1.1:80, Linux might still reply through 2.2.2.2 and the other way around. You have to configure a routing rule as per http://lartc.org/howto/lartc.rpdb.multiple-links.html to make Linux force replies for packets that entered through 1.1.1.2 out through 1.1.1.2 again, and a rule that makes replies to packets that entered through 2.2.2.2 exit through 2.2.2.2 again.

Else it would work for the people that came in at the right time (while it was the correct gateway's turn in the load balancing), and not work for people that came in at the wrong time (while it was the wrong interface's turn).

 

by: hfraserPosted on 2009-03-30 at 07:25:08ID: 24019221

I should check my old notes more thoroughly. You're right. It does matter when the multiple paths are on the host. I was thinking of redundancy in the network (multiple paths).

What makes it worse is that I recently helped a friend who pointed me to policy routing, so I should know better.

It is more complicated to set up, and unfortunately not well supported by normal graphical tools, including my favorite Webmin. In my friends case, he wanted to have application-to-application traffic go over a slower backup link, while having his user interface over the faster primary. Policy routing was the only practical way for him. Very cool stuff.

It may be necessary in this case as well, but it's not clear from the question if that's the simplest solution.

 

by: Xyptilon2Posted on 2009-03-30 at 08:28:37ID: 24019918

I cannot seem to get it to work.. I now have the following in /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        address 1.1.1.1
        netmask 255.255.254.0
        network 1.1.1.0
        broadcast 1.1.1.255
        gateway 1.1.1.2

auto eth0:0
iface eth0:0 inet static
        address 2.2.2.1
        netmask 255.255.255.0
        network 2.2.2.0
        broadcast 2.2.2.255
        gateway 2.2.2.2

But I'm not sure how to add the routing rules (i've read the page) or where to place them. I'm also not sure if it is possible using only 1 physical interface. Where should i place the routing rules?

 

by: UberpappaPosted on 2009-03-30 at 08:41:49ID: 24020032

You can write a script, lets say:

/usr/local/bin/policyrouting.sh

and then do this in the interfaces file:

auto eth0:0
iface eth0:0 inet static
        address 2.2.2.1
        netmask 255.255.255.0
        network 2.2.2.0
        broadcast 2.2.2.255
        gateway 2.2.2.2
        up /usr/local/bin/policyrouting.sh


That will make Debian call the script every time the interface goes up. At first, do it manually (without the above) until its working, then do the script with the rules in them.

The rules should look like this (not tested, so please provide feedback if I'm wrong somewhere, and we can debug):

Edit /etc/iproute2/rt_tables, and add this to the bottom:

#
# local
#
1       isp1
2       isp2

The restart your network, insure that both ip addresses are up and pingable from the local root promt. Then

        ip route add 1.1.1.0/24 dev eth0 src 1.1.1.1 table 1
        ip route add default via 1.1.1.2 table T1
        ip route add 2.2.2.0/24 dev eth0 src 2.2.2.1 table 2
        ip route add default via 2.2.2.2 table 2

Then hold thumbs that everything is working, and if so, put the above in a script and add the "up" line to the interfaces file.

 

by: UberpappaPosted on 2009-03-30 at 08:42:28ID: 24020039

Oops, remove the gateway lines from the interfaces file.

 

by: UberpappaPosted on 2009-03-30 at 08:44:27ID: 24020061

And the T1 in the second line should be 1, like so:

        ip route add 1.1.1.0/24 dev eth0 src 1.1.1.1 table 1
        ip route add default via 1.1.1.2 table 1
        ip route add 2.2.2.0/24 dev eth0 src 2.2.2.1 table 2
        ip route add default via 2.2.2.2 table 2

 

by: Xyptilon2Posted on 2009-03-30 at 09:50:38ID: 24020688

Thank you..that works...i have poored it into a script for others to use in the future and easy usage accross servers. (see below). If i run the script with hard-coded values it works, however when i enter variables at the top i get the following error message:

Error: either "to" is duplicate, or "1.1.1.1" is a garbage.
Error: either "to" is duplicate, or "2.2.2.1" is a garbage.
Error: either "to" is duplicate, or "1.1.1.1" is a garbage.
Error: either "to" is duplicate, or "2.2.2.1" is a garbage.

# Setup variables, make sure that the tablenamers are in
# /etc/iproute2/rt_table
tablename1="1"
tablename2="2"
 
ip1="1.1.1.1"
network_ip1="1.1.1.0"
gateway_ip1="1.1.1.2"
interace_ip1="eth0"
 
ip2="2.2.2.1"
network_ip2="2.2.2.0"
gateway_ip2="2.2.2.2"
interace_ip2="eth0:0"
 
# Setup the routing table for route 1
ip route add ${network_ip1} dev ${interface_ip1} src ${ip1} table ${tablename1}
ip route add default via ${gateway_ip1} table ${tablename1}
 
ip route add ${network_ip2} dev ${interface_ip2} src ${ip2} table ${tablename2}
ip route add default via ${gateway_ip2} table ${tablename2}
# -----------------------------------------------------------------
 
# Setup the main routing table
ip route add ${network_ip1}  dev ${interface_ip1} src ${ip1}
ip route add ${network_ip2}  dev ${interface_ip2} src ${ip2}
 
# -----------------------------------------------------------------
# Add default gateway
ip route add default via ${gateway_ip1}
# -----------------------------------------------------------------
 
# Specify which routing table to use based on IP
ip rule add from ${ip1} table ${tablename1}
ip rule add from ${ip2} table ${tablename2}
# -----------------------------------------------------------------

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:

Select allOpen in new window

 

by: UberpappaPosted on 2009-03-30 at 10:09:26ID: 24020881

I think you left out the subnet mask. Add a netmask_ip1 and netmask_ip2 and then do:

ip route add ${network_ip1}/${netmask_ip1} dev .... etc

 

by: Xyptilon2Posted on 2009-03-30 at 10:34:45ID: 24021151

Adding that to:

network_ip1="1.1.1.0/24"

Unfortunately didn't work. The error message is still there. However if i dont use variables, the error message does not appear?

 

by: Xyptilon2Posted on 2009-03-30 at 11:03:16ID: 24021430

My bad.. the problem was a mis-spelled variable name interace instead of interface (see above). :) Thanks for the help!

 

by: Xyptilon2Posted on 2009-03-30 at 11:04:22ID: 31563557

Thanks :)

 

by: UberpappaPosted on 2009-03-30 at 11:05:17ID: 24021445

Is it not duplicates by any change?

Try

ip route show table 1

if your routes are already in there, add a:

ip route flush table ${tablename1}
ip route flush table ${tablename2}

before adding the rules

 

by: UberpappaPosted on 2009-03-30 at 11:06:01ID: 24021455

:) Glad to help

 

by: Xyptilon2Posted on 2009-03-30 at 11:54:40ID: 24021993

Flushing the tables seem like a good idea. I have added it near the top of the script, or at least under the variable declarations. Do you know why the tablenames also have to be in /etc/iproute2/rt_tables ?

 

by: UberpappaPosted on 2009-03-30 at 12:25:54ID: 24022317

Actually I'm not sure whether its required. It seems you can add routes without the tables being in there. But all the documentation seems to indicate that you must put it in there too. You can test without it in there to see if it still works. Personally I have always added it because I was told to do so :)

 

by: UberpappaPosted on 2009-03-30 at 12:32:08ID: 24022385

Got it:

From their documentation:

Although we can work with pure numbers, it's far easier if we add our tables to /etc/iproute2/rt_tables.

So rt_tables is only if you want to use:

ip route list table isp1

instead of:

ip route list table 1

So you can ommit it.

 

by: Xyptilon2Posted on 2009-03-30 at 12:56:01ID: 24022659

Thanks ... the script is working like a charm now...though i am still getting a strange message, but it doesnt appear to affect the working of the script.. any ideas? The first two lines seem clear, but then the next 2 lines? It appears after doing an /etc/init.d/networking restart

Nothing to flush.
Nothing to flush.
RTNETLINK answers: File exists
RTNETLINK answers: File exists
done.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...