Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
08-24-2014, 01:56 PM
|
#1
|
Member
Registered: Sep 2012
Posts: 126
Rep:
|
change destination ip address to broadcast address by iptables
I want to change the destination IP address of the packets that I received.
I want to know if a solution exists by iptables to change the destination IP address of the packets to a broadcast address?
Assume I have a linux box with 2 network interfaces(eth0 and eth1) which works as a firewall.
I want to change the destination IP address of the receiving packets from eth0 to a broadcast address onto the eth1.
Is it possible to perform something like this ?
Can I perform that by Netfilter Loadable kernel Module?
Can I perform that by iptables command?
I need to specially perform that with iptables ....
|
|
|
08-26-2014, 11:12 AM
|
#2
|
Member
Registered: Jul 2007
Distribution: Fedora, CentOS, and would like to get back to Gentoo
Posts: 332
Rep:
|
If I'm understanding the question correctly, I believe it's done via PREROUTING.
This is from section 6.2 of the NAT How-To:
This is done in the PREROUTING chain, just as the packet comes in; this means that anything else on the Linux box itself (routing, packet filtering) will see the packet going to its `real' destination. It also means that the `-i' (incoming interface) option can be used.
Destination NAT is specified using `-j DNAT', and the `--to-destination' option specifies an IP address, a range of IP addresses, and an optional port or range of ports (for UDP and TCP protocols only).
## Change destination addresses to 5.6.7.8
# iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 5.6.7.8
## Change destination addresses to 5.6.7.8, 5.6.7.9 or 5.6.7.10.
# iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 5.6.7.8-5.6.7.10
## Change destination addresses of web traffic to 5.6.7.8, port 8080.
# iptables -t nat -A PREROUTING -p tcp --dport 80 -i eth0 \
-j DNAT --to 5.6.7.8:8080
|
|
|
08-26-2014, 11:32 AM
|
#3
|
Member
Registered: Sep 2012
Posts: 126
Original Poster
Rep:
|
Yes i want to DNAT but not to a specific IP address, I want to change destination IP address to a broadcast IP address.
For example the eth0 is on 192.168.0.0/24 network and eth1 is on 192.168.1.0/24.
The packets is coming on eth0 and I want to change IP address of the packets to 192.168.1.255(broadcast address).
Is it possible do that by iptables in NAT prerouting chain ??
|
|
|
08-26-2014, 12:50 PM
|
#4
|
Member
Registered: Jul 2007
Distribution: Fedora, CentOS, and would like to get back to Gentoo
Posts: 332
Rep:
|
Quote:
Originally Posted by kikilinux
Yes i want to DNAT but not to a specific IP address, I want to change destination IP address to a broadcast IP address.
For example the eth0 is on 192.168.0.0/24 network and eth1 is on 192.168.1.0/24.
The packets is coming on eth0 and I want to change IP address of the packets to 192.168.1.255(broadcast address).
Is it possible do that by iptables in NAT prerouting chain ??
|
I can't figure out how to edit/convert the ip addresses; I can only see a way to re-direct them to another destination:
Code:
iptables -t nat -A PREROUTING -i $INTERNET_IFACE1 -p tcp -d 192.168.1.0/24 -s 0.0.0.0/0 -j DNAT --to-destination 192.168.1.255
iptables -t nat -A PREROUTING -i $INTERNET_IFACE1 -p udp -d 192.168.1.0/24 -s 0.0.0.0/0 -j DNAT --to-destination 192.168.1.255
Under the "-s" part, you could specify "-s 192.168.0.0/24" but using "0.0.0.0/0" is comprehensive and thus anything coming in on eth0 will route to destination 192.168.1.255.
|
|
|
All times are GMT -5. The time now is 02:54 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|