Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 09-10-2015, 09:32 AM   #1
LQ Newbie
Registered: Jan 2012
Posts: 2

Rep: Reputation: Disabled
Routing all data from one IP to another in linux (centos)

I like to route all data that is coming in at one IP address of my server to another IP address somewhere else on the internet.

For example:
My server has 2 IP addresses: and
All the data that is coming in at IP address should be forwarded to adres (this address it not in my network)
So if I surf with a browser to this should be the same outcome as going to

I like to do this from within the console of a centos linux distro.
Old 09-10-2015, 10:43 AM   #2
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
Have a look at iptables DNAT rules.
Old 09-12-2015, 10:40 PM   #3
LQ Newbie
Registered: Jan 2015
Location: Toronto
Distribution: Xubuntu, Raspbian
Posts: 4

Rep: Reputation: Disabled
So it should be:
iptables -t nat -A PREROUTING -d -j DNAT --to-destination
Take a look here. The information enters PREROUTING, then goes into FORWARD then exits. By default forwarding is allowed but if it isn't:
iptables -A FORWARD -d -j ACCEPT
iptables -A FORWARD -s -j ACCEPT
Your kernel must also accept forwarding, edit /etc/sysctl.conf. Make sure you have net.ipv4.ip_forward = 1 and it should not be commented. After making changes to sysctl.conf reload it:
sysctl -p /etc/sysctl.conf

Last edited by dpcioc; 09-12-2015 at 11:54 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Prevent loss of personal data while installing CentOS linux shreesh Linux - Newbie 9 01-19-2014 02:08 PM
Firewall/Routing Rule in CentOS/Linux for this setup switzergtr Linux - Networking 3 12-07-2012 08:12 AM
Routing Dilemma in CentOS crazynp Linux - Networking 1 05-24-2011 06:11 AM
PPTP, Centos 5.5, Routing jamescondron Linux - Networking 8 04-24-2011 05:56 PM
routing problem on centos 5.2 Franxez Linux - Server 5 10-15-2009 10:22 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:53 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration