How do I route internet traffic over my second IP address?
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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 :-)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.