Monday 28 January 2013

configuring linux system as router


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

/etc/sysctl.conf:
net.ipv4.ip_forward = 1

configure A for NAT

Now that we have a connection from A to B, we can tell A to share internet connection with B.
  • Go to computer A and share its internet connection with B by typing the two commands :
modprobe iptable_nat
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth1 -j ACCEPT
Now you do a ping test from remote system

ping 8.8.8.8  [ should be working ]

then check ping www.google.com   [ if not working then check for /etc/resolve.conf ]
  • Run this script on the host A :
#!/usr/bin/env bash
modprobe iptable_nat
echo 1 > /proc/sys/net/ipv4/ip_forward
ifconfig eth1 192.168.0.1 netmask 255.255.255.0
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth1 -j ACCEPT


  • Run this script on the host B where xx.xx.xx.xx is your dns server :
#!/usr/bin/env bash
ifconfig eth0 down
ifconfig eth0 192.168.0.2 netmask 255.255.255.0
route del -net default 2>/dev/null
route add default gw 192.168.0.1 2>/dev/null
echo "nameserver xx.xx.xx.xx" > /etc/resolv.conf



few more links:

No comments:

Post a Comment