Centos Use As Router

Centos Use As Router Rating: 9,0/10 3904 votes
  1. Centos Use As Router Server

Apr 06, 2017  Yes, I could get a router with DD-WRT or Open WRT but I already have the PC and based on prior experience a cheap DD-WRT router will bog down with heavy traffic and I do not want to spend a lot of $$$ for a high powered wireless router as I only have one wireless device. Here is my test configuration. The PCs are running CentOS 7.3.

On this page

  1. Step-By-Step Configuration of NAT with iptables

Step-By-Step Configuration of NAT with iptables

This tutorial shows how 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. This is achieved by rewriting the source and/or destination addresses of IP packets as they pass through the NAT system.

Requirements:

CPU - PII or more
OS - Any Linux distribution
Software - Iptables
Network Interface Cards: 2

Here is my considerations:

Replace xx.xx.xx.xx with your WAN IP

Replace yy.yy.yy.yy with your LAN IP

(i.e. 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8 as suggested by Mr. tzs)

WAN = eth0 with public IP xx.xx.xx.xx
LAN = eth1 with private IP yy.yy.yy.yy/ 255.255.0.0

Step by Step Procedure

Centos Use As Router Server

Step #1. Add 2 Network cards to the Linux box

Step #2. Verify the Network cards, Wether they installed properly or not

( The output should be '2')

Step #3. Configure eth0 for Internet with a Public ( IP External network or Internet)

DEVICE=eth0
BOOTPROTO=none
BROADCAST=xx.xx.xx.255 # Optional Entry
HWADDR=00:50:BA:88:72:D4 # Optional Entry
IPADDR=xx.xx.xx.xx
NETMASK=255.255.255.0 # Provided by the ISP
NETWORK=xx.xx.xx.0 # Optional
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
GATEWAY=xx.xx.xx.1 # Provided by the ISP

Step #4. Configure eth1 for LAN with a Private IP (Internal private network)

Centos use as router setup

BOOTPROTO=none
PEERDNS=yes
HWADDR=00:50:8B:CF:9C:05 # Optional
TYPE=Ethernet
IPV6INIT=no
DEVICE=eth1
NETMASK=255.255.0.0 # Specify based on your requirement
BROADCAST='
IPADDR=192.168.2.1 # Gateway of the LAN
NETWORK=192.168.0.0 # Optional
USERCTL=no
ONBOOT=yes

Step #5. Host Configuration (Optional)

127.0.0.1 nat localhost.localdomain localhost

Step #6. Gateway Configuration

NETWORKING=yes
HOSTNAME=nat
GATEWAY=xx.xx.xx.1 # Internet Gateway, provided by the ISP

Step #7. DNS Configuration

nameserver 203.145.184.13 # Primary DNS Server provided by the ISP
nameserver 202.56.250.5 # Secondary DNS Server provided by the ISP

Step #8. NAT configuration with IP Tables

# Delete and flush. Default table is 'filter'. Others like 'nat' must be explicitly stated.

# Delete all chains that are not in default filter and nat table

# Set up IP FORWARDing and Masquerading

# Enables packet forwarding by kernel

#Apply the configuration

Step #9. Testing

# Ping the Gateway of the network from client system

Try it on your client systems

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.
• The DNS should be set to that of the ISP on the internet.
Windows '95, 2000, XP, Configuration:
• Select 'Start' + Settings' + 'Control Panel'
• Select the 'Network' icon
• Select the tab 'Configuration' and double click the component 'TCP/IP' for the ethernet card. (NOT the TCP/IP -> Dial-Up Adapter)
• Select the tabs:
o 'Gateway': Use the internal network IP address of the Linux box. (192.168.2.1)
o 'DNS Configuration': Use the IP addresses of the ISP Domain Name Servers. (Actual internet IP address)
o 'IP Address': The IP address (192.168.XXX.XXX - static) and netmask (typically 255.255.0.0 for a small local office network) of the PC can also be set here.

I have 2 PCs running CentOS 7 and they're both connected to a wireless repeater/AP. I have statically set both the IP addresses of the 2 PCs, and they are able to ping each other via IP. I have also manually set the hostname of each pc, and each PC is also able to ping itself via hostname. However, they are not able to ping each other by hostname.

I have set the DNS server to be the same as the default gateway, which is the router IP address. Is this correct? If not, what should I do?

Thanks!

user1118764user1118764

1 Answer

You will also need to propagate your hostnames + IP to your local DNS. By default it will not be able to resolve hostnames without, as it is most likely only some kind of a proxy for your provider's DNS. As I cannot say, waht you are running as router, I'd recommend to check manual how to do it.

Also you could put your hosts to the hosts-file (Windows should be something like c:windowssystem32driversetchosts). Wikipedia is having a article about. However, this would need to update the hosts file on every system trying to connect via hostname.

Centos Use As Router

Anoter way could be to use some pseudo static approach: Chenge the configuration of the router's DHCP it a way, hosts getting same IP on ever DHCP-Request. This can be done by pinning MAC-Adresse... but also need some lookup on manual.

frlanfrlan

Not the answer you're looking for? Browse other questions tagged networkingwireless-networkingdnscentosping or ask your own question.