LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Multiple IP addresses + Routing? (https://www.linuxquestions.org/questions/linux-networking-3/multiple-ip-addresses-routing-423953/)

Termina 03-11-2006 07:35 PM

Multiple IP addresses + Routing?
 
I have several static IP addresses, and would like to set up a linux box to act as a router.

If I have 3 static IP addresses, and 4 NICs in the machine (3 outgoing, 1 incoming) can I do the following?

* Assign 3 IP addresses on one (physical) interface
* Have the other three interfaces forward traffic, each depending on one of the three static IPs?

I would assume it looks something like what I put below, but I'd love it if someone could point me in the right direction. If there is a distro similar to smoothwall, only able to do this, that would be nifty as well. ;)

Code:

#Not very familar with iptables, sorry
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth0 -p ICMP -j DROP
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A INPUT -i eth2 -j ACCEPT
iptables -A INPUT -i eth3 -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth2 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth3 -o eth0 -j ACCEPT
iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -o eth2 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -o eth3 -m state --state ESTABLISHED,RELATED -j ACCEPT
#example IPs below
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 216.170.248.162
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 216.170.248.163
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 216.170.248.164


fataldata 03-11-2006 07:45 PM

Looks good. I have not done it but I do use my FC4 box as a firewall. The only point I would add is to be sure and enable forwarding with:
Code:

echo "1" > /proc/sys/net/ipv4/ip_forward


All times are GMT -5. The time now is 08:43 AM.