Tutorials:Routing multiple public ip addresses on a linux router

From Knowledge base
Revision as of 18:55, 12 March 2018 by Celogeek (talk | contribs) (Created page with "Category:Tutorials <seo title="Routing multiple public ip addresses on a linux router" metakeywords="tutorial,router,routing,public,IP,address,config" /> Let say we have a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Let say we have at least 3 connections.

One private, one public (default outgoing), and a second public.

This is a typical config /etc/network/interfaces:

auto lo
iface lo inet loopback

#private network
auto eth0
iface eth0 inet static
	address 10.90.0.1
	netmask 255.255.255.0
	post-up ip rule add to 10.90.0.0/24 lookup main prio 1000
	post-down ip rule del to 10.90.0.0/24 lookup main prio 1000

#default public network for all outgoing connection
auto eth1
iface eth1 inet static
	address YOUR_PUBLIC_IP_1
	netmask 255.255.255.255
	broadcast YOUR_PUBLIC_IP_1
	post-up route add YOUR_ROUTER_IP dev eth1
	post-up route add default gw YOUR_ROUTER_IP
	dns-nameservers YOUR_DNS
	dns-search YOUR_INTERNAL_DOMAIN

auto eth2
iface eth2 inet static
	address YOUR_PUBLIC_IP_2
	netmask 255.255.255.255
	broadcast YOUR_PUBLIC_IP_2
	post-up route add YOUR_ROUTER_IP dev eth2
	post-up ip route add default via YOUR_ROUTER_IP dev eth2 table public2
	post-up ip rule add from YOUR_PUBLIC_IP_2 lookup public22 prio 1002
	post-down ip rule del from YOUR_PUBLIC_IP_2 lookup public2 prio 1002

And you will need additional route table in /etc/iproute2/rt_tables:

#
# reserved values
#
255     local
254     main
253     default
0       unspec
#
# local
#
1 public2

So this config, create a second route table 'public2'. Any incoming connection that passes through the public IP 2 go out by this same IP.

By default, your network goes out by the default IP (public IP 1).



Share your opinion