Skip to contentSkip to conversation

Denying output to irc servers on std. tcp ports from router and behind NAT

DISCUSSION Jimmy James 3 participants 3 messages Sep 9, 2002 – Sep 10, 2002

lore
Share & tools
lore
#0 lore raw

Hi, the reason i am here is to ask how i can block access to any tcp connection with any host on ports 6666-7000. I am running Iptables 1.2.2, which came with an old slackware linux 8.0 cd.

My connection to the internet is pppoe, whereas ppp0 is the internet interface that is bonded with eth0. I only have 2 nics, one physicaly connected to the dsl modem (eth0), and the other (eth1) connected to the

hub.

<INTERNET---<ppp---<firewall---<ppp0---<eth0---<eth1---<hub---<WORKSTATIONS

           \-------->/-------->/-------->/----->/------>/----------->/

This is the best i can illustrate it.

Anyway, what I am trying to do is deny outbound access to all of irc from all my computers including the router.

I changed the output chain for the filter table on the router by typing "iptables -t filter -A OUTPUT -o ppp0 -p tcp --dport 6666:7000 -j DROP"

Once this entry was made, i could no longer connect to any irc server (that runs standard port settings) from my router.

However, on NATed machines, such as my twm workstation, I could still connect to open ports 6666:7000 on any serverr. What is wrong? Why does the iptables entry i just typed not drop outbound packets from NATed machines?

Seeing that eth0(ppp0) is the closest NIC to the internet, I figure that

an outbound packet from behind the NAT will depart to the outside from this interface. Why doesnt the filtering of output to tcp6666-7000 using the interface closest to the internet on my router apply to the internal machines? Wcan i still connect to irc from my workstation using this rule?

I did find a solution that would disable output to tcp6666-7000 from both my router and the workstations behind it. However, this solution requires that i apply an additional iptables rule.

I figure that as a NATed machine attempts to connect to a host in the outside world, it obviously goes through the router. Since the closest interface between the internal network and the router is eth1, i figure that in abstract, the routing from the workstation to the internet IRC servers goes like this:

WORKSTATION-->ROUTER(ETH1)-->ROUTER(ETH0)-->ROUTER(PPP0/ETH0)-->PPP(DSL MODEM)-->INTERNET-IRC SERVER

Considering that the iptables rule is written on the router, and since the workstation is linked to the router via eth0, I assume that the rule

must consider the packets coming from the workstation as data destined for the router (the machine handling the iptables rules).

Using the following rule, "iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 6666:7000 -j DROP,"
I am no longer able to connect to IRC servers! Good! However, while reading the IP-Tables HOWTO at
http://www.netfilter.org/documentation/tutorials/blueflux/iptables-tutorial.html,

I noticed that "Table 3-2. Destination local host (our own machine)" makes a note that one should avoid packet filtering in step 4.

WHAT IS WRONG?! Why cant i just use one iptables entry in the FILTER table using the OUTPUT chain to handle the filtered output for both my internal network and router at once?

Does anyone know of a new rule i could use, a module i need to load, or maybe an additional rule for this to work?

Thanks.

-James Stickland [Scarborough, Toronto, Ontario , Canada]

#1 lore raw

You need to apply this rule to the FORWARD chain.

The INPUT and OUTPUT chains only deal with packets for the interfaces directly attached to the iptables box.

Quoted 69 lines · Jimmy James

Hi, the reason i am here is to ask how i can block access to any tcp connection with any host on ports 6666-7000. I am running Iptables 1.2.2, which came with an old slackware linux 8.0 cd.

My connection to the internet is pppoe, whereas ppp0 is the internet interface that is bonded with eth0. I only have 2 nics, one physicaly connected to the dsl modem (eth0), and the other (eth1) connected to the

hub.

<INTERNET---<ppp---<firewall---<ppp0---<eth0---<eth1---<hub---<WORKSTATIONS

           \-------->/-------->/-------->/----->/------>/----------->/

This is the best i can illustrate it.

Anyway, what I am trying to do is deny outbound access to all of irc from all my computers including the router.

I changed the output chain for the filter table on the router by typing "iptables -t filter -A OUTPUT -o ppp0 -p tcp --dport 6666:7000 -j DROP"

Once this entry was made, i could no longer connect to any irc server (that runs standard port settings) from my router.

However, on NATed machines, such as my twm workstation, I could still connect to open ports 6666:7000 on any serverr. What is wrong? Why does the iptables entry i just typed not drop outbound packets from NATed machines?

Seeing that eth0(ppp0) is the closest NIC to the internet, I figure that

an outbound packet from behind the NAT will depart to the outside from this interface. Why doesnt the filtering of output to tcp6666-7000 using the interface closest to the internet on my router apply to the internal machines? Wcan i still connect to irc from my workstation using this rule?

I did find a solution that would disable output to tcp6666-7000 from both my router and the workstations behind it. However, this solution requires that i apply an additional iptables rule.

I figure that as a NATed machine attempts to connect to a host in the outside world, it obviously goes through the router. Since the closest interface between the internal network and the router is eth1, i figure that in abstract, the routing from the workstation to the internet IRC servers goes like this:

WORKSTATION-->ROUTER(ETH1)-->ROUTER(ETH0)-->ROUTER(PPP0/ETH0)-->PPP(DSL MODEM)-->INTERNET-IRC SERVER

Considering that the iptables rule is written on the router, and since the workstation is linked to the router via eth0, I assume that the rule

must consider the packets coming from the workstation as data destined for the router (the machine handling the iptables rules).

Using the following rule, "iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 6666:7000 -j DROP,"
I am no longer able to connect to IRC servers! Good! However, while reading the IP-Tables HOWTO at
http://www.netfilter.org/documentation/tutorials/blueflux/iptables-tutorial.html,

I noticed that "Table 3-2. Destination local host (our own machine)" makes a note that one should avoid packet filtering in step 4.

WHAT IS WRONG?! Why cant i just use one iptables entry in the FILTER table using the OUTPUT chain to handle the filtered output for both my internal network and router at once?

Quoted 17 lines

Does anyone know of a new rule i could use, a module i need to load, or maybe an additional rule for this to work?

Thanks.

-James Stickland [Scarborough, Toronto, Ontario , Canada]

[-] Steve Mickeler [ [email protected] ]

[|] Todays root password is brought to you by /dev/random

[+] 1024D/9AA80CDF = 4103 9E35 2713 D432 924F 3C2E A7B9 A0FE 9AA8 0CDF

#2 lore raw
In reply to Jimmy James

James,

Quoted 8 lines

I changed the output chain for the filter table on the router by typing "iptables -t filter -A OUTPUT -o ppp0 -p tcp --dport 6666:7000 -j DROP"

Once this entry was made, i could no longer connect to any irc server (that runs standard port settings) from my router.

Using the following rule, "iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 6666:7000 -j DROP,"

You need two rules. One in the OUTPUT chain for your router (you have this one), and one in the FORWARD chain to drop packets passing through your router (you were close).

"iptables -t nat -A FORWARD -i eth1 -p tcp --dport 6666:7000 -j DROP"

There is a good diagram in the Netfilter documentation that shows how packet flow through the firewall. The INPUT and OUTPUT chains on the firewall are for packets originating (or terminating) on the firewall. Packets passing through use the FORWARD chain. PREROUTING and POSTROUTING are used to do modify packets.

Regards,

Brad Morgan