LinuxQuestions.org
Help answer threads with 0 replies.
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 08-27-2013, 01:49 AM   #1
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Debian, Ubuntu
Posts: 400

Rep: Reputation: 39
Simple IPtables :: allow ACK packets


Hi all,

I thought I'd try and just use a simple shell script to control my firewall on a OpenVZ server as ufw fails due to a number of expected environments not being there in an OpenVZ container.

Many sites had nice simple commands to set up iptables, but all leaves me in a state where I can not get out. Doing a tcpdump I see a distinct difference.

A successful wget to an IP address with iptable rules set.

Code:
16:22:38.440189 IP serverhub02.56732 > chicago.dward.us.http: Flags [S], seq 830131992, win 14600, options [mss 1460,sackOK,TS val 37292524 ecr 0,nop,wscale 7], length 0
16:22:38.465109 IP chicago.dward.us.http > serverhub02.56732: Flags [S.], seq 1702390871, ack 830131993, win 14480, options [mss 1460,sackOK,TS val 3753499643 ecr 37292524,nop,wscale 6], length 0
16:22:39.439209 IP serverhub02.56732 > chicago.dward.us.http: Flags [S], seq 830131992, win 14600, options [mss 1460,sackOK,TS val 37293524 ecr 0,nop,wscale 7], length 0
16:22:39.464004 IP chicago.dward.us.http > serverhub02.56732: Flags [S.], seq 1702390871, ack 830131993, win 14480, options [mss 1460,sackOK,TS val 3753500642 ecr 37292524,nop,wscale 6], length 0
16:22:39.465638 IP chicago.dward.us.http > serverhub02.56732: Flags [S.], seq 1702390871, ack 830131993, win 14480, options [mss 1460,sackOK,TS val 3753500644 ecr 37292524,nop,wscale 6], length 0
16:22:41.439226 IP serverhub02.56732 > chicago.dward.us.http: Flags [S], seq 830131992, win 14600, options [mss 1460,sackOK,TS val 37295524 ecr 0,nop,wscale 7], length 0
16:22:41.464184 IP chicago.dward.us.http > serverhub02.56732: Flags [S.], seq 1702390871, ack 830131993, win 14480, options [mss 1460,sackOK,TS val 3753502642 ecr 37292524,nop,wscale 6], length 0
16:22:41.470093 IP chicago.dward.us.http > serverhub02.56732: Flags [S.], seq 1702390871, ack 830131993, win 14480, options [mss 1460,sackOK,TS val 3753502647 ecr 37292524,nop,wscale 6], length 0
16:22:45.440208 IP serverhub02.56732 > chicago.dward.us.http: Flags [S], seq 830131992, win 14600, options [mss 1460,sackOK,TS val 37299524 ecr 0,nop,wscale 7], length 0
16:22:45.465109 IP chicago.dward.us.http > serverhub02.56732: Flags [S.], seq 1702390871, ack 830131993, win 14480, options [mss 1460,sackOK,TS val 3753506643 ecr 37292524,nop,wscale 6], length 0
16:22:45.487716 IP chicago.dward.us.http > serverhub02.56732: Flags [S.], seq 1702390871, ack 830131993, win 14480, options [mss 1460,sackOK,TS val 3753506666 ecr 37292524,nop,wscale 6], length 0
16:22:53.439209 IP serverhub02.56732 > chicago.dward.us.http: Flags [S], seq 830131992, win 14600, options [mss 1460,sackOK,TS val 37307524 ecr 0,nop,wscale 7], length 0
16:22:53.464401 IP chicago.dward.us.http > serverhub02.56732: Flags [S.], seq 1702390871, ack 830131993, win 14480, options [mss 1460,sackOK,TS val 3753514642 ecr 37292524,nop,wscale 6], length 0
16:22:53.508392 IP chicago.dward.us.http > serverhub02.56732: Flags [S.], seq 1702390871, ack 830131993, win 14480, options [mss 1460,sackOK,TS val 3753514686 ecr 37292524,nop,wscale 6], length 0
The same wget call to the same IP after applying iptable rules

Code:
16:22:21.274340 IP serverhub02.56663 > chicago.dward.us.http: Flags [S], seq 3674578861, win 14600, options [mss 1460,sackOK,TS val 37275359 ecr 0,nop,wscale 7], length 0
16:22:21.299157 IP chicago.dward.us.http > serverhub02.56663: Flags [S.], seq 493537540, ack 3674578862, win 14480, options [mss 1460,sackOK,TS val 3753482478 ecr 37275359,nop,wscale 6], length 0
16:22:21.299175 IP serverhub02.56663 > chicago.dward.us.http: Flags [.], ack 1, win 115, options [nop,nop,TS val 37275383 ecr 3753482478], length 0
16:22:21.299226 IP serverhub02.56663 > chicago.dward.us.http: Flags [P.], seq 1:115, ack 1, win 115, options [nop,nop,TS val 37275383 ecr 3753482478], length 114
16:22:21.324089 IP chicago.dward.us.http > serverhub02.56663: Flags [.], ack 115, win 227, options [nop,nop,TS val 3753482503 ecr 37275383], length 0
16:22:21.418494 IP chicago.dward.us.http > serverhub02.56663: Flags [P.], seq 1:459, ack 115, win 227, options [nop,nop,TS val 3753482594 ecr 37275383], length 458
16:22:21.418511 IP serverhub02.56663 > chicago.dward.us.http: Flags [.], ack 459, win 123, options [nop,nop,TS val 37275503 ecr 3753482594], length 0
16:22:21.419041 IP serverhub02.56663 > chicago.dward.us.http: Flags [F.], seq 115, ack 459, win 123, options [nop,nop,TS val 37275503 ecr 3753482594], length 0
16:22:21.495269 IP chicago.dward.us.http > serverhub02.56663: Flags [F.], seq 459, ack 116, win 227, options [nop,nop,TS val 3753482674 ecr 37275503], length 0
16:22:21.495288 IP serverhub02.56663 > chicago.dward.us.http: Flags [.], ack 460, win 123, options [nop,nop,TS val 37275580 ecr 3753482674], length 0


The rules I am setting aren't anything tricky.

Code:
#! /bin/bash
iptables -F
iptables -X
echo Allow ssh
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
echo Allow icmp
iptables -A INPUT -p icmp -j ACCEPT
echo Allow local
iptables -A INPUT -s 127.0.0.1 -j ACCEPT
echo Allow connections already made
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i venet0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
echo Reject all other traffic
#iptables -A INPUT -j DROP
iptables -A INPUT -j DROP
iptables -A FORWARD -j DROP
The state lines I thought would allow packets to come back to a connection established from the server. But it seems not to.

I tried these rules on hardware (my desktop) and same result so I feel I am missing something.

Thanks.
 
Old 08-27-2013, 07:48 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
I think you have the successful and unsuccessful packet traces around the wrong way and a space in your shebang but regardless, please try the rules below and see if that works, I've commented them for clarity:
Code:
#!/bin/bash

# flush rules
iptables -F

# set policies
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

# accept packets related to connections initiated by us 
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# allow anything from loopback interface
iptables -A INPUT -i lo -j ACCEPT

# allow certain types of ICMP traffic 
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
iptables -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT
iptables -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT

# allow inbound ssh connections 
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
 
Old 08-27-2013, 07:53 PM   #3
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Debian, Ubuntu
Posts: 400

Original Poster
Rep: Reputation: 39
Thanks kbp
I like your succinct script there.

I have just resolved the issue. The problem was the hardware host I was on didn't have the kernel modules loaded for connection tracking.

I am glad I am not going crazy
 
Old 08-27-2013, 08:05 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Me too .. I couldn't see anything obviously wrong
 
Old 08-27-2013, 08:21 PM   #5
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Debian, Ubuntu
Posts: 400

Original Poster
Rep: Reputation: 39
Thumbs up

Right. Thanks mate.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Outgoing torrent ACK-Packets flooding my Intranet IceDragon Linux - Networking 13 01-28-2011 07:04 AM
tc filter can't match ACK packets ivanatora Linux - Networking 4 02-10-2009 03:44 PM
Disntiguishing between ACK packets in a TCP connection!! vishamr2000 Linux - Networking 3 05-23-2006 01:08 AM
searching for a WLAN card which is able to capture ACK and other management packets! lackyg Linux - Wireless Networking 1 02-03-2006 09:34 PM
Forwarding ACK Packets snufferz Linux - Newbie 0 05-12-2004 02:10 AM

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

All times are GMT -5. The time now is 11:14 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