U
U
Un_ka2021-11-29 16:59:54
linux
Un_ka, 2021-11-29 16:59:54

How to forward a device port from one local network to another?

I have such a network:
61a4dc32c454a350083818.jpeg
How to connect via telnet from the terminal addressing 192.168.100.22:23 to port 23 of the 4g modem.
How can I do it?
Previously, it seemed to turn this by raising a proxy on the Raspberry pi, but this seems to be possible using iptables.
List of network interfaces on Raspberry pi:

ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
   
    inet 192.168.0.144/24 brd 192.168.0.255 scope global noprefixroute usb0
       valid_lft forever preferred_lft forever
    inet6 fe80::361d:208c:a91f:2c78/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
   
    inet 192.168.100.22/24 brd 192.168.100.255 scope global noprefixroute wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::bc36:60bd:72c5:2b80/64 scope link
       valid_lft forever preferred_lft forever

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2021-11-29
@ky0

The usual way to do this is with the packet forward rule in iptables/nft.

U
Un_ka, 2021-12-03
@Un_ka

I got an answer on the Linux forum .
We leave these answers here so that they can help others too.
Through iptables:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -d 192.168.100.22 -p tcp --dport 23 -j DNAT --to-destination 192.168.0.1:23
iptables -t nat -A POSTROUTING -d 192.168.0.1 -p tcp --dport 23 -j SNAT --to-source 192.168.0.144

Temporary via socat:
socat TCP-LISTEN:23,fork TCP:192.168.0.1:23

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question