Port is open but I am unable to connect
When I add -s 1.2.3.4 I am unable to connect to my server. nmap shows that the correct ports are open.
Any ideas?
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 22 -m state --state NEW
This is my script:
<script>
#!/bin/sh
# Modules
modprobe ip_conntrack_ftp
# Defaults
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# Flush
iptables -t nat -F POSTROUTING
iptables -t nat -F PREROUTING
iptables -t nat -F OUTPUT
iptables -F
# STATE RELATED for router
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Localhost
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# Open ports on router for server/services
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 20 -m state --state NEW iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 21 -m state --state NEW iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 22 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 25 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 80 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 143 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 993 -m state --state NEW </script>
Thanks,
Jacob
just to make sure.. you are certain, that you want -s 1.2.3.4?
this means source ip is 1.2.3.4 (so the ip you connect from, not the ip you connect _to_)
Quoted 49 lines · Jacob Friis Larsen
When I add -s 1.2.3.4 I am unable to connect to my server. nmap shows that the correct ports are open.
Any ideas?iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 22 -m state --state NEW
This is my script:
<script>
#!/bin/sh# Modules
modprobeip_conntrack_ftp# Defaults
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP# Flush
iptables -t nat -F POSTROUTING
iptables -t nat -F PREROUTING
iptables -t nat -F OUTPUT
iptables -F# STATE RELATED for router
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT# Localhost
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT# Open ports on router for server/services
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 20 -m state --state NEW
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 21 -m state --state NEW
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 22 -m state --state NEW
iptables -A INPUT -j ACCEPT -p tcp --dport 25 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 80 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 143 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 993 -m state --state NEW </script>Thanks,
Jacob
Quoted 6 lines · Jacob Friis Larsen
When I add -s 1.2.3.4 I am unable to connect to my server. nmap shows that the correct ports are open.
Any ideas?iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 22 -m state --state NEW
i would content that while you believe your source IP is 1.2.3.4 in this scenario--it; in fact, is not.
try:
iptables -A INPUT -j LOG --log-prefix "FW DROP INPUT: "
and see what the logs have to say about it.
-j
Signature · 1 line
Jason Opperisano <[email protected]>
Quoted 8 lines · Jacob Friis Larsen
When I add -s 1.2.3.4 I am unable to connect to my server. nmap shows that the correct ports are open.
Any ideas?iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 22 -m state --state NEW
This is my script:
[snip]
Quoted 7 lines
# STATE RELATED for router
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT# Localhost
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
Quoted 11 lines
# Open ports on router for server/services
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 20 -m state --state NEW
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 21 -m state --state NEW
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 22 -m state --state NEW
iptables -A INPUT -j ACCEPT -p tcp --dport 25 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 80 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 143 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 993 -m state --state NEW
All your rules (apart from lo interface) are for INPUT chain. No rules for OUTPUT chain (so all return packets get dropped there). You are missing "-A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT" at the begginging of your rules (just after similar INPUT line you already have).
BTW, what's the point of accepting connections to port 20? It's FTP port used for active data transfers, and connections are made *from* it, not *to* it. Since you have (will have) "just accept anything related I don't care" rules, just add "modprobe ip_nat_ftp" line somewhere into your script, and FTP will work (you don't need that port 20 line).
Signature · 3 lines
Aleksandar Milivojevic <[email protected]> Pollard Banknote Limited Systems Administrator 1499 Buffalo Place Tel: (204) 474-2323 ext 276 Winnipeg, MB R3T 1L7
Quoted 1 line
just to make sure.. you are certain, that you want -s 1.2.3.4?
No 1.2.3.4 is just for the example :)
I don't dare to show my real ip, in case of a bad iptables script.
Thanks,
Jacob
Quoted 2 lines
i would content that while you believe your source IP is 1.2.3.4 in this scenario--it; in fact, is not.
I know.
1.2.3.4 is just for the example :)
Quoted 5 lines
try:
iptables -A INPUT -j LOG --log-prefix "FW DROP INPUT: "
and see what the logs have to say about it.
This will log all incoming packets?
Thanks,
Jacob
Quoted 5 lines
All your rules (apart from lo interface) are for INPUT chain. No rules for OUTPUT chain (so all return packets get dropped there). You are missing "-A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT" at the begining of your rules (just after similar INPUT line you already have).
Sounds logic. I changed it in the script below, and will try it out later when I can get to the server.
Quoted 6 lines
BTW, what's the point of accepting connections to port 20? It's FTP port used for active data transfers, and connections are made *from* it, not *to* it. Since you have (will have) "just accept anything related I don't care" rules, just add "modprobe
ip_nat_ftp" line somewhere into your script, and FTP will work (you don't need that port 20 line).
OK, I changed that too.
Thanks a lot!
Jacob
Quoted 4 lines
Quoted 1 line
This is my script:
[snip]
modprobe ip_nat_ftp
Quoted 2 lines
Quoted 2 lines
# STATE RELATED for router
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Quoted 6 lines
Quoted 6 lines
# Localhost
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT# Open ports on router for server/services
#iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 20 -m state
Quoted 9 lines
Quoted 9 lines
--state NEW
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 21 -m state --state NEW
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 22 -m state --state NEW
iptables -A INPUT -j ACCEPT -p tcp --dport 25 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 80 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 143 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 993 -m state --state NEW
Quoted 6 lines · Jacob Friis Larsen
Quoted 2 lines
i would content that while you believe your source IP is 1.2.3.4 in this scenario--it; in fact, is not.
I know.
1.2.3.4 is just for the example :)
Quoted 7 lines
Quoted 5 lines
try:
iptables -A INPUT -j LOG --log-prefix "FW DROP INPUT: "
and see what the logs have to say about it.
This will log all incoming packets?
setting the above as you last rule, in combination with setting the POLICY of the INPUT chain to DROP, will log all packets dropped by the INPUT chain. similarly:
iptables -A OUTPUT -j LOG --log-prefix "FW DROP OUTPUT: "
will log all packets dropped by the OUTPUT chain; which in your case, should show you what Aleksandar already pointed out--you don't allow ESTABLISHED packets out through the OUTPUT chain.
-j
Signature · 1 line
Jason Opperisano <[email protected]>
With the changes I still can't connect. I also use bonding if that's important.
<script>
#!/bin/sh
# Modules
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
# Defaults
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# Flush
iptables -t nat -F POSTROUTING
iptables -t nat -F PREROUTING
iptables -t nat -F OUTPUT
iptables -F
# STATE RELATED for router
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Localhost
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# Open ports on router for server/services
#iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 20 -m state --state NEW iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 21 -m state --state NEW iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 22 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 25 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 80 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 143 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 993 -m state --state NEW </script>
Quoted 2 lines · Jacob Friis Larsen
With the changes I still can't connect. I also use bonding if that's important.
dunno about bonding...might be important.
Quoted 26 lines
<script>
#!/bin/sh# Modules
modprobeip_conntrack_ftp
modprobeip_nat_ftp# Defaults
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP# Flush
iptables -t nat -F POSTROUTING
iptables -t nat -F PREROUTING
iptables -t nat -F OUTPUT
iptables -F# STATE RELATED for router
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT# Localhost
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
Quoted 12 lines
# Open ports on router for server/services
#iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 20 -m state --state NEW
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 21 -m state --state NEW
iptables -A INPUT -s 1.2.3.4 -j ACCEPT -p tcp --dport 22 -m state --state NEW
iptables -A INPUT -j ACCEPT -p tcp --dport 25 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 80 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 143 -m state --state NEW iptables -A INPUT -j ACCEPT -p tcp --dport 993 -m state --state NEW </script>
just to clarify a point--the services your trying to connect to *are* running locally on the machine running netfilter, correct? the only reason i ask, is because the comment "Open ports on router for server/services" leads me to believe that "router" and "server" are two different machines. if "server" is behind "router" you should be using FORWARD filter rules, not INPUT...
anyways...at this point--i'd recommend:
iptables -A INPUT -j LOG --log-prefix "FW DROP IN: " iptables -A OUTPUT -j LOG --log-prefix "FW DROP OUT: " iptables -A FORWARD -j LOG --log-prefix "FW DROP FWD: "
and then "tail -f /var/log/messages" and try to connect. the logs will tell you why the firewall is dropping the traffic.
-j
Signature · 1 line
Jason Opperisano <[email protected]>