Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] How can I open port 80? Newbie Iptables problem...
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
marcion
Apprentice
Apprentice


Joined: 14 Mar 2005
Posts: 158
Location: England

PostPosted: Mon Dec 12, 2005 12:06 am    Post subject: [solved] How can I open port 80? Newbie Iptables problem... Reply with quote

I have a little network:

A. Server/Router with Hardened Gentoo (Selinux etc) no X server, on 24/7
B. Desktop, (turned off when not in use)

-A has cable modem plugged in, this gives internet access to B - this bit works fine.
-I have installed Apache on A, and need to open port 80 which is being blocked by IPtables (when I stop IPtables, the website works).

IP tables on router was setup according to:
http://www.gentoo.org/doc/en/home-router-howto.xml#doc_chap5_sect3

I have been googling for two hours for a rule to cut and paste but they all didn't work (perhaps because I am not synthesizing the examples enough with the above router guide). What is the command I need to allow people outside to access Apache?


Last edited by marcion on Mon Dec 12, 2005 1:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
aaronamd
n00b
n00b


Joined: 13 Oct 2005
Posts: 59

PostPosted: Mon Dec 12, 2005 12:23 am    Post subject: Reply with quote

iptables -A INPUT -p TCP --dport 80 -i [interface] -j ACCEPT

put the external interface ( the one that is connected to the net) where the word interface is, and remove the brackets around it and you should be set to serve! :D

and don't forget to save the table state so it'll come back up when you reboot
to do that do:
/etc/init.d/iptables save

good luck
_________________
http://zigtech.net/forum
Back to top
View user's profile Send private message
marcion
Apprentice
Apprentice


Joined: 14 Mar 2005
Posts: 158
Location: England

PostPosted: Mon Dec 12, 2005 6:33 am    Post subject: Reply with quote

aaronamd wrote:
iptables -A INPUT -p TCP --dport 80 -i [interface] -j ACCEPT


Does not seem to work :( - is this conflicting with one of the other IPtables rules?

Quote:


First we flush our current rules
# iptables -F
# iptables -t nat -F

Setup default policies to handle unmatched traffic
# iptables -P INPUT ACCEPT
# iptables -P OUTPUT ACCEPT
# iptables -P FORWARD DROP

Copy and paste these examples ...
# export LAN=eth1
# export WAN=eth0

Then we lock our services so they only work from the LAN
# iptables -I INPUT 1 -i ${LAN} -j ACCEPT
# iptables -I INPUT 1 -i lo -j ACCEPT
# iptables -A INPUT -p UDP --dport bootps -i ! ${LAN} -j REJECT
# iptables -A INPUT -p UDP --dport domain -i ! ${LAN} -j REJECT

(Optional) Allow access to our ssh server from the WAN
# iptables -A INPUT -p TCP --dport ssh -i ${WAN} -j ACCEPT

Drop TCP / UDP packets to privileged ports
# iptables -A INPUT -p TCP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP
# iptables -A INPUT -p UDP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP

Finally we add the rules for NAT
# iptables -I FORWARD -i ${LAN} -d 192.168.0.0/255.255.0.0 -j DROP
# iptables -A FORWARD -i ${LAN} -s 192.168.0.0/255.255.0.0 -j ACCEPT
# iptables -A FORWARD -i ${WAN} -d 192.168.0.0/255.255.0.0 -j ACCEPT
# iptables -t nat -A POSTROUTING -o ${WAN} -j MASQUERADE
Tell the kernel that ip forwarding is OK
# echo 1 > /proc/sys/net/ipv4/ip_forward
# for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done

This is so when we boot we don't have to run the rules by hand
# /etc/init.d/iptables save
# rc-update add iptables default
# nano /etc/sysctl.conf
Add/Uncomment the following lines:
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1


Back to top
View user's profile Send private message
MrUlterior
Guru
Guru


Joined: 22 Mar 2005
Posts: 511
Location: Switzerland

PostPosted: Mon Dec 12, 2005 10:24 am    Post subject: Reply with quote

Your port 80 rule must appear before:
Code:
# iptables -A INPUT -p TCP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP
# iptables -A INPUT -p UDP -i ! ${LAN} -d 0/0 --dport 0:1023 -j DROP

_________________

Misanthropy 2.0 - enough hate to go around
Back to top
View user's profile Send private message
marcion
Apprentice
Apprentice


Joined: 14 Mar 2005
Posts: 158
Location: England

PostPosted: Mon Dec 12, 2005 1:46 pm    Post subject: Reply with quote

Thanks everyone - it works now !
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum