LinuxQuestions.org
Visit Jeremy's Blog.
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-05-2024, 01:25 AM   #1
ganeshrockz
LQ Newbie
 
Registered: Jan 2024
Posts: 1

Rep: Reputation: 0
Query related to introducing traffic redirection rules with iptables


I am trying to forward localhost DNS requests in an alpine container deployed in an ECS task that are originally intended to port 53 to port 8700 where I have a custom DNS resolver running on my box.

I have made sure to add 127.0.0.1 as the first nameserver in /etc/resolv.conf

To support traffic redirection I added the following commands to modify iptable NAT rules

Code:
/# iptables -t nat -N DNS_REDIRECT
/# iptables -t nat -A DNS_REDIRECT -p udp -d 127.0.0.1 --dport 53 -j DNAT --to-destination 127.0.0.1:8700
/# iptables -t nat -A OUTPUT -p udp -d 127.0.0.1 --dport 53 -j DNS_REDIRECT

This is output of the rules present in the NAT table

Code:
/ # iptables -t nat -L -v
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 110 packets, 7653 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   39  3693 DNS_REDIRECT  udp  --  any    any     anywhere             localhost            udp dpt:domain

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain DNS_REDIRECT (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   39  3693 DNAT       udp  --  any    any     anywhere             localhost            udp dpt:domain to:127.0.0.1:8700

The DNS server on 8700 is running fine and serving responses properly. I was able to verify this with dig -p 8700 foo.com.

On executing dig foo.com, I get the following error

;; communications error to 127.0.0.1#53: timed out
;; communications error to 127.0.0.1#53: timed out
;; communications error to 127.0.0.1#53: timed out
;; communications error to 127.0.0.1#53: timed out
;; communications error to 127.0.0.1#53: timed out


From application logs, I can see that the DNS server has responded back with the correct response, but iptable rules are somehow mangling the UDP packets. Can someone help me debug this further?
 
  


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
Please help with IPTables rules to route all TCP & UDP traffic of a user through a SOCKS5 proxy terente0081 Linux - Newbie 3 10-03-2021 07:37 AM
[SOLVED] /etc/udev/rules.d/40-libsane.rules and /etc/udev/rules.d/S99-2000S1.rules missing LABEL=libsane_rules_end mumahendras3 Slackware 6 03-09-2020 02:27 AM
auditctl -l not showing any rules even though i have rules written in audit.rules alphaguy Linux - Security 1 02-07-2014 05:28 PM
[SOLVED] Traffic redirection using iptables wooly Linux - Newbie 7 11-23-2010 07:29 PM
iptables rules to bridge traffic scheidel21 Linux - Networking 2 08-31-2007 12:05 PM

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

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