How to configure Linux as router for sharing internet in RHEL?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux (RHEL).

Issue

  • How to share internet in Linux?
  • Local system must route the traffic to router server to access the internet.

Resolution

  • Refer following steps to configure Linux system as router and share internet :

    • Assign static ip address's to eth0 and eth1 interfaces.

    • Enable ip forwarding using following command :

      • Enable ip forwarding
      # echo 1 > /proc/sys/net/ipv4/ip_forward
      
      • To make this change persistent across reboot, add the following line in "/etc/sysctl.conf"
    net.ipv4.ip_forward = 1
    
    • Add iptables to share internet from eth1 interface.
    # iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
    
    • Save and restart iptables.
    # service iptables save
    # service iptables restart
    
    • Set ip of eth0 interface as gateway in all our local systems .

    • Make sure the dns is proper.

    • Now we are all set to share internet connection from Linux system.

  • Another best thing to share internet is using squid proxy. With squid server its easy to share the internet as well as restrict/allow usres/ip using squid server. Squid proxy has lot of useful feature .

Refer : How to configure squid in Red Hat Enterprise Linux

Root Cause

  • IP forwarding allows functionality to configure system as router.
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.