Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Easiest way to specify the outgoing IP on a VPS with multiple IPs?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Easiest way to specify the outgoing IP on a VPS with multiple IPs?

My knowledge of nix is minimal (I can usually do/google enough to do basic things like run automated installers, manually go through and modify basic config files, follow guides, etc). My question is essentially the same as what another person posted here: http://www.questionhub.com/ServerFault/128169

Actually, there are two questions:

Q1) If I have a VPS with two or more IPv4 addresses, what is the easiest way to set it up such that if I connect (for the purpose of SSH tunneling) to IP 1, the outgoing IP will be IP 1, that connecting to IP2 will use IP2 as the outgoing IP, etc. For this question, I specifically want to SSH tunnel, not use a VPN.

Q2) What would be the easiest way to achieve the same set up as in Q1, except through (password-protected) SOCKS5 proxies instead of SSH tunneling?

I'm interested in both scenarios because while the setup in #2 would be more convenient (and fine for random surfing), I would presume that #1 is more secure (for example, if I am surfing private data from public wifi).

Thanks for letting me pick your collective nose brains :).

Comments

  • Anyone?

  • Which distro do you use?

  • user123user123 Member
    edited February 2014

    @dhamaniasad said:
    Which distro do you use?

    Debian 6 (32-bit) is my preferred default

  • FrankZFrankZ Veteran
    edited February 2014

    I don't do much in Debian, so I will not give routing advise, but have you tried iptables nat?

    If the service is running on < IP2 >

    iptables -t nat -A POSTROUTING -s < IP2 > -j SNAT --to-source < IP2 >

    Thanked by 1user123
  • SNAT is the only way

  • user123user123 Member
    edited February 2014

    Thanks, FrankZ and joereid. I'll try that command once the second IP is set up on my VPS.

  • Like everyone said SNAT is the way to go

  • change main IP in SolusVM?

  • user123user123 Member
    edited February 2014

    @FrankZ said:
    I don't do much in Debian, so I will not give routing advise, but have you tried iptables nat?

    If the service is running on < IP2 >

    iptables -t nat -A POSTROUTING -s < IP2 > -j SNAT --to-source < IP2 >

    @FrankZ @joereid @cosmicgate
    The command didn't work :(. IP1 still shows up as the IP when I surf after connecting to the VPS through IP2.

    @DalComp said:
    change main IP in SolusVM?

    I want to be able to use both IPs.

  • You can try snat/postrouting by uid:

    adduser proxy1
    id -u proxy1
    iptables -m owner -t nat -A POSTROUTING --uid-owner <proxy1 uid> -j SNAT --to <IP1>
    adduser proxy2
    id -u proxy2
    iptables -m owner -t nat -A POSTROUTING --uid-owner <proxy2 uid> -j SNAT --to <IP2>
    

    Then you can connect through SSH/tunnel/etc with proxy1 to use IP1 and proxy2 to use IP2

  • user123user123 Member
    edited February 2014

    @SegmentationFault said:
    You can try snat/postrouting by uid:

    adduser proxy1
    id -u proxy1
    iptables -m owner -t nat -A POSTROUTING --uid-owner <proxy1 uid> -j SNAT --to <IP1>
    adduser proxy2
    id -u proxy2
    iptables -m owner -t nat -A POSTROUTING --uid-owner <proxy2 uid> -j SNAT --to <IP2>
    

    Then you can connect through SSH/tunnel/etc with proxy1 to use IP1 and proxy2 to use IP2

    Thanks, this worked :)

Sign In or Register to comment.