LinuxQuestions.org
Review your favorite Linux distribution.
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 09-10-2015, 09:32 AM   #1
mmvika
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: 1.1.1.1 and 2.2.2.2
All the data that is coming in at IP address 2.2.2.2 should be forwarded to adres 3.3.3.3 (this address it not in my network)
So if I surf with a browser to http://2.2.2.2/ this should be the same outcome as going to http://3.3.3.3/

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

Rep: Reputation: Disabled
Hello!
So it should be:
Code:
iptables -t nat -A PREROUTING -d 2.2.2.2 -j DNAT --to-destination 3.3.3.3
Take a look here. The information enters PREROUTING, then goes into FORWARD then exits. By default forwarding is allowed but if it isn't:
Code:
iptables -A FORWARD -d 3.3.3.3 -j ACCEPT
iptables -A FORWARD -s 3.3.3.3 -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:
Code:
sysctl -p /etc/sysctl.conf

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


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
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

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

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