LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-07-2013, 08:56 AM   #1
Barskalas
LQ Newbie
 
Registered: Apr 2013
Posts: 2

Rep: Reputation: Disabled
Question Iptables


Hello everybody,

I have to do school project with iptables, and after a week of trying to understand iptables I still didnt figure out how to do my project. So maybe someone here can help me.

I have to make .sh scripts. First one should let everybody on the network use only http and https. Second one should let only two computers on the network to use http and https.

Eth0 is IN and Eth1 is OUT.

I would be very thankful if someone could help me.

Last edited by Barskalas; 04-07-2013 at 09:14 AM.
 
Old 04-07-2013, 09:15 AM   #2
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
So what have you done to this point.
For example: did you take an existing linux box with an active firewall and made a listing of the rules and studied them.
What rules did already write.

Cheers
 
Old 04-07-2013, 09:24 AM   #3
Barskalas
LQ Newbie
 
Registered: Apr 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Until now, I studied about linux scripts, and learned few basics about iptables. Still newbie in linux. I ask for help because I have not much time left to show this project. It took me a while to understand the task it self.
 
Old 04-07-2013, 10:07 AM   #4
Lexus45
Member
 
Registered: Jan 2010
Distribution: Debian, Centos, Ubuntu, Slackware
Posts: 361
Blog Entries: 3

Rep: Reputation: 48
  • Assuming, your router's internal IP is 192.168.0.1, internal network is 192.168.0.0/24 and external IP is 12.13.14.15, your LAN clients can reach only HTTP (tcp/80) and HTTPS (tcp/443) outside:
Code:
#!/bin/bash
firewall_start() {
    iptables -F
    iptables -t nat -F
    iptables -t mangle -F

# Setting default policies
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

# makros
GATE_LAN_HOME="192.168.0.0/24"
GATE_LAN_HOME_IP="192.168.0.1"
GATE_WAN="12.13.14.15"


###### NAT
iptables -t nat -A POSTROUTING		-s $GATE_LAN_HOME -o eth1 -j SNAT --to $GATE_WAN


##### INCOMING #####
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -s 127.0.0.0/8 -d 127.0.0.0/8 -i lo -j ACCEPT


######## FORWARDING #########
iptables -A FORWARD -p all -s $GATE_LAN_HOME --dport 80,443 -i eth0 -o eth1 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT


}

firewall_stop() {
    iptables -F
    iptables -t nat -F
}
firewall_restart() {
    firewall_stop
    sleep 1
    firewall_start
}

case "$1" in
'start')
  firewall_start
  ;;
'stop')
  firewall_stop
  ;;
'restart')
  firewall_restart
  ;;
*)
echo "usage $0 start|stop|restart"
esac
  • Assuming, your router's internal IP is 192.168.0.1, internal network is 192.168.0.0/24 and external IP is 12.13.14.15, your LAN clients with IP addresses 192.168.0.8 and 192.168.0.19 can reach only HTTP (tcp/80) and HTTPS (tcp/443) outside:
Code:
#!/bin/bash
firewall_start() {
    iptables -F
    iptables -t nat -F
    iptables -t mangle -F

# Setting default policies
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP

# makros
GATE_LAN_HOME="192.168.0.0/24"
GATE_LAN_HOME_IP="192.168.0.1"
GATE_WAN="12.13.14.15"


###### NAT
iptables -t nat -A POSTROUTING		-s $GATE_LAN_HOME -o eth1 -j SNAT --to $GATE_WAN


##### INCOMING #####
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -s 127.0.0.0/8 -d 127.0.0.0/8 -i lo -j ACCEPT


######## FORWARDING #########
iptables -A FORWARD -p all -s 192.168.0.8  --dport 80,443 -i eth0 -o eth1 -j ACCEPT
iptables -A FORWARD -p all -s 192.168.0.19 --dport 80,443 -i eth0 -o eth1 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT


}

firewall_stop() {
    iptables -F
    iptables -t nat -F
}
firewall_restart() {
    firewall_stop
    sleep 1
    firewall_start
}

case "$1" in
'start')
  firewall_start
  ;;
'stop')
  firewall_stop
  ;;
'restart')
  firewall_restart
  ;;
*)
echo "usage $0 start|stop|restart"
esac
This script must be executable. If you'll place it as me (/etc/rc.d/rc.firewall , but it may depend on your distribution), do 'chmod +x /etc/rc.d/rc.firewall' and tell your system to load it at startup. In my case it's done in /etc/rc.d/rc.local .
You may also start/stop/restart it by typing /etc/rc.d/rc.firewall start (or stop or restart).

Last edited by Lexus45; 04-07-2013 at 10:20 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables error in android: iptables-save and iptables-restore not working preetb123 Linux - Mobile 5 04-11-2011 01:56 PM
On what basis CHAIN integer values are generated in IPtables under iptables file? haariseshu Linux - Server 3 11-05-2009 04:25 AM
iptables v1.2.9: Unknown arg `/sbin/iptables' Try `iptables -h' or 'iptables --help' Niceman2005 Linux - Security 4 12-29-2005 08:20 PM
Iptables - Couldn't load target `ACCPET':/lib/iptables/libipt_ACCPET.so: z00t Linux - Security 3 01-26-2004 02:24 AM
My iptables script is /etc/sysconfig/iptables. How do i make this baby execute on boo ForumKid Linux - General 3 01-22-2002 07:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration