0

I would like to know how can I force the use of port 22 to the interface I want, any interface, Wi-Fi or Ethernet.
For example route *:22 to Wi-Fi.
I checked route command but it looks like it's not possible.
Any idea?
BSD or Linux commands are welcome.

5
  • 1
    I would like to nominate you for Worst Question Ever. Which OS? Are you connected both via ethernet and via wireless? Do you want to ssh into a LAN pc, or a WAN machine? Dec 8, 2015 at 9:45
  • Sorry, I always think Linux&BSD are the only OS available, I always forgot that people run could imagine running Windows.
    – VivienG
    Dec 8, 2015 at 9:55
  • The ones answered in my question?
    – VivienG
    Dec 8, 2015 at 10:31
  • The question is already GREATLY answered, it looks like the question was not so incomprehensible. BTW, can you stop editing my question with no improvement PLEASE!
    – VivienG
    Dec 8, 2015 at 10:50
  • I agree correcting it's look likes into it looks like is a small improvement. Dec 8, 2015 at 11:38

1 Answer 1

4

Regular routing only works in terms of IP addresses and doesn't concern itself with what data (including TCP or UDP) is transferred.


At least on Linux, you could use policy routing for this:

  1. Add a firewall rule to mark certain packets:

    iptables -t mangle -A PREROUTING -p tcp --dport 22 -j MARK --set-mark 1
    
  2. Create a new routing table with your desired gateway:

    ip route add default via 192.168.0.1 dev wlan0 table 42
    
  3. Add a policy rule to use the new routing table for marked packets:

    ip rule add fwmark 1 table 42
    

On Windows, you'll need a different approach, for example, telling the program to use a specific interface. Some programs have a "bind address" option, such as ssh's -b:

ssh -b 192.168.0.42 root@myserver

(I don't know how well it works with multiple interfaces, though. I have a feeling it might not.)


Finally, you could add a host route (via Wi-Fi) towards a specific server.

This could be extended to enabling SSH tunnelling through that server for all your other connections.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .