Thread View: comp.os.linux.networking
7 messages
7 total messages
Started by Koen Van de Velde
Fri, 03 Jan 2003 16:17
IPTables vs. DNS (or : iptables doesn't change sourceport when MASQ'ing)
Author: Koen Van de Velde
Date: Fri, 03 Jan 2003 16:17
Date: Fri, 03 Jan 2003 16:17
108 lines
5206 bytes
5206 bytes
Hi, Since I converted my ipchains-rules to iptables, my local DNS-server doesn't work anymore. this is the config : (local DNS-server: 192.168.102.13) 192.168.102.0/24 LAN | | 192.168.102.5 Linux (kernel 2.4.18, iptables v1.2.5) 213.224.999.999 | | INTERNET (an internet DNS-server : 195.0.51.66) If I use these (simplified) ipchains-firewall, everything works fine : #!/bin/sh /sbin/modprobe ipchains echo 1 > /proc/sys/net/ipv4/ip_forward /sbin/ipchains -F forward /sbin/ipchains -P forward DENY /sbin/ipchains -A forward -s 192.168.102.0/24 -j MASQ /sbin/ipchains -A forward -s 0.0.0.0/0 -d 0.0.0.0/0 -j DENY /sbin/ipchains -F input /sbin/ipchains -P input ACCEPT /sbin/ipchains -F output /sbin/ipchains -P output ACCEPT As we can proof with this tcpdump-output (after a local workstation started a 'ping www.stubru.be') : * on internal interface (before MASQ) 13:36:39.697718 192.168.102.13.domain > 195.0.51.66.domain: \ 8292 A? www.stubru.be. (31) 13:36:39.766156 195.0.51.66.domain > 192.168.102.13.domain: \ 8292* 1/0/0 A 195.0.110.51 (47) * or the same on external interface (after MASQ) 13:36:39.697744 213.224.999.999.61000 > 195.0.51.66.domain: \ 8292 A? www.stubru.be. (31) 13:36:39.766132 195.0.51.66.domain > 213.224.999.999.61000: \ 8292* 1/0/0 A 195.0.110.51 (47) As you can see : on the external interface, the Ip-adress AND PORT-number are translated (from domain=53 to 61000). Then I changed the ipchains-rules to this iptables config : #!/bin/sh EXTDEV=eth1 echo 1 > /proc/sys/net/ipv4/ip_forward /sbin/iptables --flush /sbin/iptables -X /sbin/iptables -t nat -A POSTROUTING -o $EXTDEV -j MASQUERADE /sbin/iptables -P FORWARD ACCEPT /sbin/iptables -P INPUT ACCEPT /sbin/iptables -P OUTPUT ACCEPT and all of a sudden, the external dns-requests of my dns-server stop working. As proven by this tcpdump-output (after a local workstation started a 'ping www.donna.be') : * on internal interface (before MASQ) 14:02:34.808729 192.168.102.13.domain > 198.6.1.82.domain: \ 8688 A? www.donna.be. (30) 14:02:35.804819 192.168.102.13.domain > 198.6.1.82.domain: \ 2559 A? www.donna.be. (30) 14:02:36.897332 192.168.102.13.domain > 134.58.40.4.domain: \ 8688 A? www.donna.be. (30) 14:02:37.808455 192.168.102.13.domain > 198.6.1.82.domain: \ 4608 A? www.donna.be. (30) 14:02:37.899344 192.168.102.13.domain > 134.58.40.4.domain: \ 2559 A? www.donna.be. (30) .... these kind of messages appear a hunderd times .... * or the same on external interface (after MASQ) 14:02:34.808965 213.224.999.999.domain > 198.6.1.82.domain: \ 8688 A? www.donna.be. (30) 14:02:35.804930 213.224.999.999.domain > 198.6.1.82.domain: \ 2559 A? www.donna.be. (30) 14:02:36.897465 213.224.999.999.domain > 134.58.40.4.domain: \ 8688 A? www.donna.be. (30) 14:02:37.808571 213.224.999.999.domain > 198.6.1.82.domain: \ 4608 A? www.donna.be. (30) 14:02:37.899388 213.224.999.999.domain > 134.58.40.4.domain: \ 2559 A? www.donna.be. (30) .... these kind of messages appear a hunderd times .... As you can see : on the external interface, the IP-address is MASQ'ed, but the port NOT !! This is the reason why we don't get any answer back on these requests, because our provider does block incomming trafic for port 53. And therefor the local dns-server keeps sending requests to the different internet dns-servers hoping it will ever get an answer. IN SHORT : Why doesn't the MASQ-module of iptables translate the portnumber when it's MASQ'ing (and ipchains did !) ?? First I thought it wasn't doing this for DNS-request only, but taking a closer look, it doesn't do this for any service. So if two computers in my LAN start an http-request from their local port 1026, my linux-router/firewall will sent them both out with the same source-port. I'm wondering what kind of effect this wil have ! Sorry for this rather long post, but since it's such a strange behaviour, I thought that a detailed explanation was necessary. Thanx in advance for your assistance, Koen.
Re: IPTables vs. DNS (or : iptables doesn't change sourceport when MASQ'ing)
Author: John Armstrong
Date: Fri, 03 Jan 2003 16:32
Date: Fri, 03 Jan 2003 16:32
47 lines
3081 bytes
3081 bytes
On Fri, 03 Jan 2003 16:17:39 GMT, nospam.koen.vdvelde@advalvas.be
(Koen Van de Velde) wrote:
>Hi,
>
>Since I converted my ipchains-rules to iptables, my local DNS-server
>doesn't work anymore.
>
snip
>As you can see : on the external interface, the IP-address is MASQ'ed,
>but the port NOT !! This is the reason why we don't get any answer
>back on these requests, because our provider does block incomming
>trafic for port 53. And therefor the local dns-server keeps sending
>requests to the different internet dns-servers hoping it will ever get
>an answer.
Assuming bind is being used, has /etc/named.conf been altered? My copy
has the following comment:
* Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
>
>IN SHORT :
>Why doesn't the MASQ-module of iptables translate the portnumber when
>it's MASQ'ing (and ipchains did !) ??
man iptables :
--to-ports port[-port]
This specifies a range of source ports to use, overriding the
default SNAT source port-selection heuristics (see above). This
is only valid if the rule also specifies -p tcp or -p udp.
>First I thought it wasn't doing this for DNS-request only, but taking
>a closer look, it doesn't do this for any service.
>So if two computers in my LAN start an http-request from their local
>port 1026, my linux-router/firewall will sent them both out with the
>same source-port. I'm wondering what kind of effect this wil have !
Not an expert, but presumably the de-masq'ing process sorts it out and
sends the reply packets back where they should go. Not sure how it
would work if both requests were going the the same destination
though.
--
John
Re: IPTables vs. DNS (or : iptables doesn't change sourceport when MASQ'ing)
Author: Koen Van de Velde
Date: Fri, 03 Jan 2003 17:06
Date: Fri, 03 Jan 2003 17:06
54 lines
3478 bytes
3478 bytes
On Fri, 03 Jan 2003 16:32:23 +0000, John Armstrong <ja@ggrove.swinternet.co.uk> wrote: Hi John, thanks for your response [snip again] > >Assuming bind is being used, has /etc/named.conf been altered? My copy >has the following comment: > * Previous versions of BIND always asked > * questions using port 53, but BIND 8.1 uses an unprivileged > * port by default. > */ > // query-source address * port 53; > it's not Bind, it's M$ ;-( (ssstt, don't tell anyone) but it's ok for me that (on the local network) it acts as a dns-server and therefor sents its requests to other dns-servers FROM (and to) port 53. >> >>IN SHORT : >>Why doesn't the MASQ-module of iptables translate the portnumber when >>it's MASQ'ing (and ipchains did !) ?? >man iptables : > --to-ports port[-port] > This specifies a range of source ports to use, overriding the > default SNAT source port-selection heuristics (see above). This > is only valid if the rule also specifies -p tcp or -p udp. I think this one is more used for redirection. eg: incomming packets on port 8000 on external interface of router should be redirected to other internal machine on port 80 (then the --to-ports 80 should be used). As described in 6.2.1 of the NAT-howto. >>First I thought it wasn't doing this for DNS-request only, but taking >>a closer look, it doesn't do this for any service. >>So if two computers in my LAN start an http-request from their local >>port 1026, my linux-router/firewall will sent them both out with the >>same source-port. I'm wondering what kind of effect this wil have ! >Not an expert, but presumably the de-masq'ing process sorts it out and >sends the reply packets back where they should go. Not sure how it >would work if both requests were going the the same destination >though. I thought it would give each outgoing packet a new unique source-port (let's say: starting from 61000). When the packets come back, it can check this port, look it up in it's NAT-table, and forward the packet to the original requester. As far as I know, this is how ipchains worked. Now it seems that iptables is doing it different, Or I did something wrong with my configuration, Or I'm using a buggy version of iptables. K.
Re: IPTables vs. DNS (or : iptables doesn't change sourceport when MASQ'ing)
Author: Jan Pieter
Date: Sat, 04 Jan 2003 14:59
Date: Sat, 04 Jan 2003 14:59
14 lines
1980 bytes
1980 bytes
Koen Van de Velde wrote: > I thought it would give each outgoing packet a new unique source-port > (let's say: starting from 61000). When the packets come back, it can > check this port, look it up in it's NAT-table, and forward the packet > to the original requester. As far as I know, this is how ipchains > worked. > Now it seems that iptables is doing it different, Or I did something > wrong with my configuration, Or I'm using a buggy version of iptables. Both ipchains and iptables only change the address, not ports - unless you specifically configure them to do so. Jan Pieter.
Re: IPTables vs. DNS (or : iptables doesn't change sourceport when MASQ'ing)
Author: John Armstrong
Date: Mon, 06 Jan 2003 10:12
Date: Mon, 06 Jan 2003 10:12
22 lines
2219 bytes
2219 bytes
On Fri, 03 Jan 2003 17:06:20 GMT, nospam.koen.vdvelde@advalvas.be (Koen Van de Velde) wrote: >On Fri, 03 Jan 2003 16:32:23 +0000, John Armstrong ><ja@ggrove.swinternet.co.uk> wrote: > >>man iptables : >> --to-ports port[-port] >> This specifies a range of source ports to use, overriding the >> default SNAT source port-selection heuristics (see above). This >> is only valid if the rule also specifies -p tcp or -p udp. >I think this one is more used for redirection. eg: incomming packets >on port 8000 on external interface of router should be redirected to >other internal machine on port 80 (then the --to-ports 80 should be >used). As described in 6.2.1 of the NAT-howto. That would be the --to-ports option of the REDIRECT target, which gives a range of destination ports, while the --to-ports option of MASQUERADE gives a range of source ports. -- John
Re: IPTables vs. DNS (or : iptables doesn't change sourceport when MASQ'ing)
Author: Koen Van de Velde
Date: Mon, 06 Jan 2003 12:02
Date: Mon, 06 Jan 2003 12:02
35 lines
2493 bytes
2493 bytes
On Mon, 06 Jan 2003 10:12:13 +0000, John Armstrong
<ja@ggrove.swinternet.co.uk> wrote:
>On Fri, 03 Jan 2003 17:06:20 GMT, nospam.koen.vdvelde@advalvas.be
>(Koen Van de Velde) wrote:
>
>>On Fri, 03 Jan 2003 16:32:23 +0000, John Armstrong
>><ja@ggrove.swinternet.co.uk> wrote:
>>
>
>>>man iptables :
>>> --to-ports port[-port]
>>> This specifies a range of source ports to use, overriding the
>>> default SNAT source port-selection heuristics (see above). This
>>> is only valid if the rule also specifies -p tcp or -p udp.
>>I think this one is more used for redirection. eg: incomming packets
>>on port 8000 on external interface of router should be redirected to
>>other internal machine on port 80 (then the --to-ports 80 should be
>>used). As described in 6.2.1 of the NAT-howto.
>
>That would be the --to-ports option of the REDIRECT target, which
>gives a range of destination ports, while the --to-ports option of
>MASQUERADE gives a range of source ports.
>--
>John
Hi John,
I changed my masq-lines to :
/sbin/iptables -t nat -A POSTROUTING -s 192.168.102.13 -p udp \
--sport 53 -o $EXTDEV -j MASQUERADE --to-port 61000:65095
/sbin/iptables -A POSTROUTING -t nat -o $EXTDEV -j MASQUERADE
and this works fine now !
thanks for your assistance,
Koen.
Re: IPTables vs. DNS (or : iptables doesn't change sourceport when MASQ'ing)
Author: John Armstrong
Date: Mon, 06 Jan 2003 12:37
Date: Mon, 06 Jan 2003 12:37
25 lines
2191 bytes
2191 bytes
On Mon, 06 Jan 2003 12:02:56 GMT, nospam.koen.vdvelde@advalvas.be
(Koen Van de Velde) wrote:
>
>Hi John,
>I changed my masq-lines to :
> /sbin/iptables -t nat -A POSTROUTING -s 192.168.102.13 -p udp \
> --sport 53 -o $EXTDEV -j MASQUERADE --to-port 61000:65095
You might want to add a line
/sbin/iptables -t nat -A POSTROUTING -s 192.168.102.13 -p tcp \
--sport 53 -o $EXTDEV -j MASQUERADE --to-port 61000:65095
As I understand it, if the dns reply is over a certain size, it goes
by tcp rather than udp, so while everything will work most of the time
without this, it will sometimes fail.
> /sbin/iptables -A POSTROUTING -t nat -o $EXTDEV -j MASQUERADE
>and this works fine now !
>
>thanks for your assistance,
>Koen.
--
John
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads