Link to home
Start Free TrialLog in
Avatar of bercko21
bercko21

asked on

How do i redirect all traffic from public IP to another public ip?

Hi,
I have a machine in a shared hosting, it listen to varies udp ports.
I like to move it to a private cage, but the IP address can't move with it.
is there any way, maybe using linux or such,
to do a simple redirect to all traffic coming to the original IP to the new IP address?

I've checked IPTABLES, but I'm still not sure how can it be done...

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Blaz
Blaz
Flag of Slovenia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you wish to redirect all traffic you could drop the "-p udp --dport 2000" parts of the rules. Note that if this is the only public IP of the linux box you will not be able to connect to it at all (like SSH).

iptables -t filter -A FORWARD -d <your hosting box IP> -m state -state NEW,ESTABLISHED -j ACCEPT
...
iptables -t nat -A PREROUTING -d <linux box IP> -j DNAT --to-destination <your hosting box IP>
iptables -t nat -A POSTROUTING -d <your hosting box IP> -j SNAT --to-source <linux box IP>
Avatar of bercko21
bercko21

ASKER

Thanks Blaz for your help!

By ports or all trafiic, both are fine,
I've tried typing the solution you brought and I'm getting "Bad argument `NEW,ESTABLISHED'"
any ideas regarding it?
I think I made a typo. The rule should read:
iptables -t filter -A FORWARD -d <your hosting box IP> -p udp --dport 2000 -m state --state NEW,ESTABLISHED -j ACCEPT

Note the double hypen before state.
Thanks!
I notice the typo, it didn't make a difference...
I still trying it here, but so far It's not working for some reason....
SOLUTION
Avatar of Arty K
Arty K
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I believe that I gave a working configuration to solve the question in comment #23708908. The only problem asker was having should be resolved by Nopius's comment #23733446 and the asker did not report any problems with the solution afterwards.