Linux Gateway Server

8:04 PM

Gateway Server Setup :

We need to set up network-address-translation (NAT) on a Linux system with iptables rules so that the system can act as a gateway and provide internet access to multiple hosts on a local network using a single public IP address.
Step by Step Procedure
==================
Step 1. Add 2 Network cards to the Linux box
Step 2. Verify the Network cards, check if they installed properly or not
Step 3. Configure Bond0 for Internet with a Public (External network or Internet)
cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
IPADDR=206.10.20.20
NETMASK=255.255.255.0
GATEWAY=206.10.20.1
Step 4. Configure eth1 for LAN with a Private IP (Internal private network)
cat /etc/sysconfig/network-scripts/ifcfg-bond1
DEVICE=bond1
BOOTPROTO=none
ONBOOT=yes
IPADDR=10.100.20.50    # Gateway of the LAN
NETMASK=255.255.255.0
Step 5. Host Configuration    (Optional)
127.0.0.1       servername localhost.localdomain   localhost
Step 6. Gateway Configuration
    NETWORKING=yes
    HOSTNAME=servername
    GATEWAY=206.10.20.1     # Internet Gateway, provided by the ISP
Step 7. DNS Configuration
# cat /etc/resolv.conf
        nameserver 201.22.22.22      # Primary DNS Server provided by the ISP
        nameserver 201.22.22.23      # Secondary DNS Server provided by the ISP
Step 8. NAT configuration with IP Tables
First of all you have to flush and delete existing firewall rules. So flush rules by typing in terminal:
    iptables -F
    iptables -t nat -F
    iptables -t mangle -F
Now delete these chains:
    iptables -X
    iptables -t nat -X
    iptables -t mangle -X
# Set up IP FORWARDing and Masquerading
    iptables -t nat -A POSTROUTING -o bond0-j MASQUERADE
    iptables -A FORWARD -i bond1 -j ACCEPT
# Enables packet forwarding by kernel (save this setting in /etc/sysctl.conf file)
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
if you already have an entry net.ipv4.ip_forward with the value 0 you can change that 1.
To enable the changes made in sysctl.conf you will need to run the command:
sysctl -p /etc/sysctl.conf
 #Apply the configuration
    service iptables save
    service iptables restart
 # Check if iptables is set to start during boot up
    chkconfig --list iptables
Step 9. Testing
Ping the Gateway of the network from client system: ping *...*
Try it on your client systems: ping google.com
Configuring PCs on the network (Clients)
All PC's on the private office network should set their "gateway" to be the local private network IP address of the Linux gateway computer.
cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
IPADDR=10.100.20.102
NETMASK=255.255.255.0
GATEWAY=10.100.20.50
and then restart network service.

You Might Also Like

0 comments

Contact Form

Name

Email *

Message *

Translate

Wikipedia

Search results