CentOS / Redhat Linux Internet Connection Sharing

CentOS / Redhat Linux Internet Connection Sharing

To set up Internet connection sharing on a CentOS or Red Hat Linux system, you can use the iptables command to configure Network Address Translation (NAT). NAT allows multiple devices on a private network to share a single public IP address and access the Internet.

To set up NAT, you will need to configure the network interface that connects to the Internet (also known as the "outside" interface) and the network interface that connects to the private network (also known as the "inside" interface).

Here are the steps to set up NAT on a CentOS or Red Hat Linux system:

  1. Identify the names of the outside and inside interfaces. You can use the ip command to list the available interfaces on your system:
refe‮r‬ to:lautturi.com
ip link show
  1. Enable IP forwarding by adding the following line to the /etc/sysctl.conf file:
net.ipv4.ip_forward = 1
  1. Load the new kernel parameters by running the following command:
sysctl -p
  1. Configure NAT using the iptables command. Replace eth0 with the name of the outside interface and eth1 with the name of the inside interface:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
  1. Save the iptables rules so they will be applied on boot:
service iptables save

This will set up NAT on your system and allow devices on the private network to access the Internet.

Created Time:2017-10-27 14:56:37  Author:lautturi