CentOS as an internet gateway.

Issues related to configuring your network
Post Reply
hack3rcon
Posts: 458
Joined: 2014/11/24 11:04:37

CentOS as an internet gateway.

Post by hack3rcon » 2019/08/02 07:49:10

Hello,
I have a CentOS server with twp NICs. One NIC is NAT and connected to the internet and another is for local network:

Code: Select all

# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:fe2e:5818  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:2e:58:18  txqueuelen 1000  (Ethernet)
        RX packets 21664  bytes 12777139 (12.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10376  bytes 1034705 (1010.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.2  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::a00:27ff:fe08:ee20  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:08:ee:20  txqueuelen 1000  (Ethernet)
        RX packets 3941  bytes 402106 (392.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 627  bytes 65331 (63.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 22  bytes 2408 (2.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 22  bytes 2408 (2.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
I'm using "enp0s3" for connect to the Internet. The "enp0s8" NIC configuration is as below:

Code: Select all

TYPE=Ethernet
BOOTPROTO=static
NETMASK=255.255.255.0
TYPE=Ethernet
HWADDR=08:00:27:08:ee:20
IPADDR=192.168.0.2
GATEWAY=192.168.0.2
NAME=enp0s8
DEVICE=enp0s8
ONBOOT=yes
I installed DHCP service and configured it as below:

Code: Select all

subnet 192.168.0.0 netmask 255.255.255.0 {
	option routers 192.168.0.2;
	option domain-name-servers 192.168.0.2;
	option broadcast-address 192.168.0.255;
	range 192.168.0.3 192.168.0.253;
        DHCPDARGS="enp0s8";
}
Then I enabled IP forwarding:

Code: Select all

# nano /etc/sysctl.conf
net.ipv4.ip_forward = 1
And using below iptables rules for give internet to the clients:

Code: Select all

# iptables -A FORWARD -o enp0s3 -i enp0s8 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
# iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# iptables -t nat -F POSTROUTING
# iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE
But my Windows client can't see the internet :(.
What is my problem?

Thank you.

hack3rcon
Posts: 458
Joined: 2014/11/24 11:04:37

Re: CentOS as an internet gateway.

Post by hack3rcon » 2019/08/02 08:21:48

I should have DNS server too? I can ping IP but not name.

hack3rcon
Posts: 458
Joined: 2014/11/24 11:04:37

Re: CentOS as an internet gateway.

Post by hack3rcon » 2019/08/02 09:00:58

I added below line to "dhcpd.conf" and problem solved:

Code: Select all

prepend domain-name-servers 8.8.8.8,4.2.2.1; 
And below rule is enough:

Code: Select all

# iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE

Post Reply

Return to “CentOS 7 - Networking Support”