I have a linux server in my lab(hereafter called pc1), and I have a windows pc2 where I have a game server running on. But since it's a private network, and the only pc that the internet can access is the pc1. But I want the game server on pc2 be seen by outside internet. But I have no access permission to the router of our lab. So I want the pc1 to act as some kind of router that forwards pc1:port1 to pc2:port2 and backwards. And then the request from outside internet can access pc2:port2 and reply from pc2 can also reach the outside. Is there any method to achieve this?
Let us call eth0 the interface (IF) on which pc1 is linked to the router, and eth1 the IF on which pc1 is linked to pc2. You need these commands, issued as sudo, on pc1:
On the Windows machine, you will have to configure a static IP in the 192.168.27.0/24 range, for instance 192.168.27.2, and set 192.168.27.1 as your default gateway.
This works on Debian-like systems. If you have another distro you will have to adapt it to your needs. For instance, on Systemd-distros (Arch-Linux, Fedora, SuSE 19..), the first command is
The first command disables the networkmanager, which hinders most custom operations. The following 3 commands connect pc1 to your router, and the further commands 5-6 connect pc1 to pc2. Then commands 7-8 set up the routing table, commands 9-10 set up DNS, command 11 enables in-kernel Ipv4 forwarding, and commands 12-13 set up rules for iptables to act as a NAT forwarder, and to accept connections from pc2.
This can be easily scripted.
If you only want to allow communication on certain ports, replace