LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 01-01-2017, 10:19 PM   #1
fabioca
LQ Newbie
 
Registered: Sep 2015
Posts: 13

Rep: Reputation: Disabled
Problem with iptables logging dhcp messages


I have a problem capturing dhcp messages with IPTables.

If I run
Code:
tcpdump -n -i lan src 192.168.69.1 and udp port 67
I can clearly see the DHCP replies going from the server (192.168.69.1) source port 67 to destination port 68.
Code:
12:09:16.678311 IP 192.168.69.1.67 > 192.168.69.4.68: BOOTP/DHCP, Reply, length 300
12:10:38.361074 IP 192.168.69.1.67 > 192.168.69.37.68: BOOTP/DHCP, Reply, length 300
12:12:03.224814 IP 192.168.69.1.67 > 192.168.69.34.68: BOOTP/DHCP, Reply, length 300
I am trying to log the same messages with iptables, so I insert the following rules:

Code:
iptables -t filter -I INPUT 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "FIL-INP:"
iptables -t filter -I OUTPUT 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "FIL-OUT:"
iptables -t filter -I FORWARD 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "FIL-FOR:"
iptables -t nat -I INPUT 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "NAT-INP:"
iptables -t nat -I OUTPUT 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "NAT-OUT:"
iptables -t nat -I PREROUTING 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "NAT-PRE:"
iptables -t nat -I POSTROUTING 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "NAT-POS:"
iptables -t mangle -I PREROUTING 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "MAN-PRE:"
iptables -t mangle -I POSTROUTING 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "MAN-POS:"
iptables -t mangle -I INPUT 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "MAN-INP:"
iptables -t mangle -I OUTPUT 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "MAN-OUT:"
iptables -t mangle -I FORWARD 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "MAN-FOR:"
iptables -t raw -I PREROUTING 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "RAW-PRE:"
iptables -t raw -I OUTPUT 1 -s 192.168.69.1 -p udp -m udp --sport 67 -j LOG --log-prefix "RAW-OUT:"

But none of the rules is hit and nothing gets logged. What is special about these dhcp replies? Why they do not match my filter criteria?

Last edited by fabioca; 01-01-2017 at 10:23 PM. Reason: Grammar errors
 
Old 01-03-2017, 12:31 PM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
First question is what is the IP address of your DHCP server? Is it 192.168.69.1? And is this also the system where you are trying to LOG the DCHP requests?

IF the DHCP server and IPTABLES are the same system then try the following:
Code:
iptables -I OUTPUT 1 --dport 68 -j LOG --log-prefix "DHCP-Reply: "
If they are not on the same system then try:
Code:
iptables -I FORWARD 1 --dport 68 -j LOG --log-prefix "DHCP-Reply: "
 
Old 01-07-2017, 11:26 AM   #3
fabioca
LQ Newbie
 
Registered: Sep 2015
Posts: 13

Original Poster
Rep: Reputation: Disabled
Tried what suggested, but it still does not work.

After some more search I think I found out the reason.

In my raw table I am filtering for
Code:
iptables -t nat -A PREROUTING -m rpfilter --invert -j DROP
This drops the incoming dhcp messages from 0.0.0.0:68 to 255:255:255:255.67

No incoming message, no reply!

Despite that the dhcp exchange still succeeds, because I am using ISC's dhcp server, which apparently has the ability to intercept messages at a lower network level, therefore in effect bypassing the firewall.

Last edited by fabioca; 01-07-2017 at 11:27 AM. Reason: typos
 
Old 01-07-2017, 02:50 PM   #4
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
I highly doubt that DHCP can bypass the firewall. This is more of a case that something else is handing out the DCHP address and not your system. You should be able to look at the logs on that system requesting the IP Address and it should show you what device gave it to him.
 
Old 01-07-2017, 08:58 PM   #5
fabioca
LQ Newbie
 
Registered: Sep 2015
Posts: 13

Original Poster
Rep: Reputation: Disabled
There are no other dhcp servers. And I can see incoming and outgoing packets in tcpdump, but not in netfilter.

What I mentioned below is based on this thread:
https://www.mail-archive.com/dnsmasq.../msg10962.html
which states:
"ISC dhcpd uses raw sockets, and those are (like tcpdump) seen before the netfilter subsystem."
 
Old 01-09-2017, 06:55 AM   #6
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
So you are seeing the complete transaction in tcpdump? Discovery Offer Request Acknowledge? Even your link states that the whole process is not possible.

I believe that since your system had an ip addrerss before it is just using it again.
Have you tried to release the address and obtain a new one?
 
Old 02-17-2017, 06:31 PM   #7
fabioca
LQ Newbie
 
Registered: Sep 2015
Posts: 13

Original Poster
Rep: Reputation: Disabled
No, tcpdump only shows 2 of the DORA messages, however this seems sufficient for dhcpd to do its job: it has been working fine for at least 1 year now, including for new wireless devices of guests visiting my house for the first time.

Anyway, I have now modified the reverse filtering logic (disabled it in the kernel and selectively activated it in iptables), so that I can see the full set of DORA messages passing thorugh ipfilter.
 
  


Reply



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
Logging of dhcpcd messages raypen Slackware 7 01-25-2015 12:17 PM
logging messages from my program doesn't reach /var/log/messages rajas Programming 4 09-18-2011 12:38 AM
[SOLVED] help with firestarter, dhcp problem, iptables tr1pl3x Linux - Networking 1 09-09-2010 12:04 AM
DHCP Problem when logging on to computer Brian.Boyle Linux - Networking 1 11-05-2003 08:41 AM
DHCP Problem when logging on to computer Brian.Boyle Linux - Networking 1 11-04-2003 07:27 PM

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

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