Link to home
Start Free TrialLog in
Avatar of ltpitt
ltpitt

asked on

Iptables rule to allow communication to specific IPs

Hi everyone!

I have a Linux firewall:

eth0 LAN
eth1 INTERNET
eth2 LAN2

I want to let LAN users use internet and ONLY specific computers on LAN2

I've tried this without luck, what am I doing wrong?


#!/bin/sh

PATH=/usr/sbin:/sbin:/bin:/usr/bin

#
# delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X

iptables -A FORWARD -o eth0 -d 192.168.1.1 -j ACCEPT
iptables -A FORWARD -o eth0 -d 192.168.1.2 -j ACCEPT
iptables -A FORWARD -o eth0 -d 192.168.1.0/24 -j DROP

# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT

# Allow established connections, and those not coming from the outside
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i ! eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCE                                   PT

# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT

# Masquerade.
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

# Enable or disable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward
#echo 0 > /proc/sys/net/ipv4/ip_forward
ASKER CERTIFIED SOLUTION
Avatar of Arty K
Arty K
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ltpitt
ltpitt

ASKER

Perfectly working!