LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2010, 03:51 PM   #1
FireRaven
Member
 
Registered: Apr 2006
Location: Australia
Distribution: Debian Squeeze
Posts: 135

Rep: Reputation: 18
How do I route internet traffic over my second IP address?


Hi,

My ISP has given me 3 IP addresses to use for the internet (76.148.200.3, 76.148.200.4 and 76.148.200.5).

If I do a "wget whatismyip.com" or netcat into another server, I am appearing as 76.148.200.3.

How do I change my route (command line) in linux to route internet traffic through 76.148.200.5?



Code:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback


# The primary network interface
auto eth0
iface eth0 inet static
        address 76.148.200.3
        netmask 255.255.255.248
        network 76.148.200.0
        broadcast 76.148.200.7
        gateway 76.148.200.1
	dns-nameservers 4.2.2.2


auto eth0:0
iface eth0:0 inet static
        address 76.148.200.4
        netmask 255.255.255.248
        network 76.148.200.0
        broadcast 76.148.200.7
        gateway 76.148.200.1
	dns-nameservers 4.2.2.2


auto eth0:1
iface eth0:1 inet static
        address 76.148.200.5
        netmask 255.255.255.248
        network 76.148.200.0
        broadcast 76.148.200.7
        gateway 76.148.200.1
	dns-nameservers 4.2.2.2




Here's the into if I type "ip route":

Code:
root@ubuntu:~# ip route
76.148.200.0/29 dev eth0  proto kernel  scope link  src 76.148.200.3
default via 76.148.200.1 dev eth0  src 76.148.200.5  metric 100
default via 76.148.200.1 dev eth0  src 76.148.200.4  metric 100
default via 76.148.200.1 dev eth0  metric 100
 
Old 03-04-2010, 04:35 PM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
The easy way would be to configure eth0 as 76.148.200.5 and eth0:1
as 76.148.200.3.
 
Old 03-04-2010, 04:41 PM   #3
FireRaven
Member
 
Registered: Apr 2006
Location: Australia
Distribution: Debian Squeeze
Posts: 135

Original Poster
Rep: Reputation: 18
But I want the hard way or I learn nothing
 
Old 03-04-2010, 04:50 PM   #4
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 99
lol. I guess you get nothing from me!
 
Old 03-04-2010, 06:51 PM   #5
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Try to delete default and add new one:
ip route add default via 76.148.200.1 dev eth0:1
 
Old 03-04-2010, 10:24 PM   #6
FireRaven
Member
 
Registered: Apr 2006
Location: Australia
Distribution: Debian Squeeze
Posts: 135

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by nimnull22 View Post
Try to delete default and add new one:
ip route add default via 76.148.200.1 dev eth0:1

I tried that but it shows in routing table as eth0 (not eth0:1) and still goes through first one.
 
Old 03-04-2010, 11:17 PM   #7
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Quote:
Originally Posted by FireRaven View Post
I tried that but it shows in routing table as eth0 (not eth0:1) and still goes through first one.
It is not just first one - it is your physical interface. I think it will never let you make default route through alias.You can give, as you were suggested already, different IP to eth0.

Last edited by nimnull22; 03-05-2010 at 10:03 AM.
 
Old 03-08-2010, 04:35 PM   #8
FireRaven
Member
 
Registered: Apr 2006
Location: Australia
Distribution: Debian Squeeze
Posts: 135

Original Poster
Rep: Reputation: 18
Ok guess I'll have to do that, thanks.
 
Old 03-09-2010, 09:40 AM   #9
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,677
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Routing determines where packets go to. If all your IP addresses have the same destination gateway, then the routing will be the same no matter which you want to use as your "source address".

The "source address" is your address on packets you originate. For incoming connections (e.g. if you are running a server) the "source address" for the return packets will be the one the connection was established with. But for packets you originate (make a connection to somewhere on the internet) then a decision has to be made. That decision can be made by the application when it sets up the sockets. Most applications don't do that. So then the decision is made by the network stack. When that happens, the decision is the first IP address matching the specified address family, for an interface the outgoing route will work on. It will probably be the first usable interface if the applicable route is not interface specific.

So use carltm's easy way ... it's THE WAY. If you really want a hard way, then write a program in assembly language to write the /etc/network/interfaces file directly ... that should be plenty hard enough :-)
 
Old 03-09-2010, 02:04 PM   #10
FireRaven
Member
 
Registered: Apr 2006
Location: Australia
Distribution: Debian Squeeze
Posts: 135

Original Poster
Rep: Reputation: 18
I worked out one way to do it...
Code:
iptables -t nat -A POSTROUTING -j SNAT --to 76.148.200.5
It feels like a bit of a hack but it sure works!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't route traffic between ppp0 and ppp1 Jongi Debian 1 04-15-2007 05:35 AM
Can I route web traffic to 2 different hosts based on URL under 1 IP Address? Marshalle Linux - Networking 5 05-14-2005 03:02 AM
dhcp no ip address and netmask dont match route address pengy666 Linux - Wireless Networking 1 05-08-2005 09:33 AM
route any traffic between two NICs thirumala Linux - Networking 0 03-24-2004 05:54 PM
Route traffic like a hub atlesn Linux - Networking 2 03-21-2004 04:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration