I am trying to demonstrate TCP communication with a Ubuntu 18.04 box (which mocks a QNX setup) that does not have a listener installed. Consider that due to some license issues it might not be possible to load and run a listener program any time soon either. Is it possible to use iptables to accept connection from a client, receive incoming packets and send them back to the client?
If yes, what are the commands? I want to use netcat to demonstrate sending and receiving of messages.
I have tried following command from this link.
echo 1 > /proc/sys/net/ipv4/ip_forward
sysctl -w net.ipv4.conf.ens4.route_localnet=1
sudo iptables -A FORWARD -i ens4 -o ens4 -m state --state RELATED,ESTABLISHED -j ACCEPT
I have also tried below commands from another StackOverflow question.
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination <IP>:80
sudo iptables -t nat -I OUTPUT -p tcp --dport 80 -j DNAT --to-destination <IP>:80
But netcat exits immediately. Not sure whether it even attempted connection.
netcat <IP> 80
Other ideas than iptables are also welcome.