I have two interfaces with one that is a shared internet usb connection from my android phone.
enp0s31f6
: ethernet internet connection (default)enp0s20f0u1
: shared connection android
I would like to use enp0s20f0u1
interface to access through ssh to only one IP. I mean, everything that will be connected to A.B.C.D
(external/internet ip) have to go through this interface. Nothing else.
I am using Centos 7.
How can I route every packets that have
A.B.C.D
as destination IP to useenp0s20f0u1
interface ?Do I need to use
ip route
oriptables
is enough ? Why ?
I am pretty new in "ip routing", please give me explanation with your answer.
Details:
enp0s20f0u1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.42.174 netmask 255.255.255.0 broadcast 192.168.42.255
enp0s31f6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.128.1.21 netmask 255.255.254.0 broadcast 10.128.1.255
What I did:
$ip route:
default via 10.128.0.1 dev enp0s31f6 proto static metric 100
default via 192.168.42.129 dev enp0s20f0u1 proto static metric 101
10.128.0.0/23 dev enp0s31f6 proto kernel scope link src 10.128.1.21 metric 100
10.136.80.66 via 10.128.0.1 dev enp0s31f6 proto dhcp metric 100
192.168.42.0/24 dev enp0s20f0u1 proto kernel scope link src 192.168.42.174 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
My interface's ip is 192.168.42.174 and the gateway for this interface is 192.168.42.129
.
I removed the second line as dirkt
said :
default via 192.168.42.129 dev enp0s20f0u1 proto static metric 101
$ ip route
default via 10.128.0.1 dev enp0s31f6 proto static metric 100
10.128.0.0/23 dev enp0s31f6 proto kernel scope link src 10.128.1.21 metric 100
10.136.80.66 via 10.128.0.1 dev enp0s31f6 proto dhcp metric 100
A.B.C.D via 192.168.42.129 dev enp0s20f0u1
192.168.42.0/24 dev enp0s20f0u1 proto kernel scope link src 192.168.42.174 metric 100
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
I don't want to use this interface for anything else that ABCD. Should I remove
192.168.42.0/24 dev enp0s20f0u1 proto kernel scope link src 192.168.42.174 metric 100
too ? I guess no, looks like it's for the LAN network of my interface.
I made a mistake, I use the interface's ip for the via
instead of the gateway.
Everything is working well now. It's more clear.
Subsidiary question just for the understanding, if now I want to redirect only the port 22 and block everything else. I guess I need iptables/firewallD, to reject everything with ABCD as dest IP and to allow only the port 22.