NAT router on Linux

Overview

This is a method of configuring a NAT router on Linux and NATing and communicating with one of the addresses of two VLANs. The content is for verification purposes and does not take security into consideration. Please be careful during production operation.

Assumed scenario

Suppose you have a VLAN operated by the following two organizations.

VLAN1: 192.168.1.0/24 VLAN2: 10.0.0.0/24

Now suppose you want to access 10.0.0.100 on VLAN2 from 192.168.1.100 on VLAN1. The VLAN1 side organization assumes that the 10.0.0.0/24 address is being used for other purposes, and the VLAN1 side makes the 10.0.0.100 address visible to 192.168.2.100. On the VLAN2 side, on the other hand, 192.168.1.100 can be accessed without address translation.

Setup steps

  1. Install CentOS 8 and connect to VLAN1 and VLAN2. Let VLAN1 be eth1 and VLAN2 be eth2.
  2. Disable SELinux because it is troublesome. Just set `SELINUX = disabled``` in `/ etc / selinux / config```.
  3. Also, disable firewalld. `` `systemctl disable firewalld```
  4. Enable the routing function. Add `net.ipv4.ip_forward = 1``` to `/etc/sysctl.conf```.
  5. Reboot for activation.
  6. Set NAT with iptables.
# iptables -t nat -A POSTROUTING -d 192.168.1.100 -j SNAT --to-source      192.168.2.100
# iptables -t nat -A PREROUTING  -d 192.168.2.100 -j DNAT --to-destination 10.0.0.100

The first line translates the source address to 192.168.2.100 when a packet with a destination of 192.168.1.100 is received. The second line translates the destination address to 10.0.0.100 when the destination receives a packet of 192.168.2.100. Specify PREROUTING so that the destination address is translated and then routed. This setting disappears when you restart, so please execute it every time you start. (I didn't know how to persist)

Recommended Posts

NAT router on Linux
Check TTL on Linux router
Daemonizing processes on Linux
jblas on Arch Linux
Linux (WSL) on Windows
Develop .NET on Linux
Wake on lan on Linux
Monitor traffic on Linux
Update vscode on linux
Try NeosVR on Linux
Check capacity on Linux
LiveUSB creation on Linux
Linux operation on Win10
NTP configuration memo on Linux
Install Minecraft on Arch Linux
Downgrade Mcomix on Arch Linux
Monitor disk usage on Linux
Use Github Desktop on Linux
Install the JDK on Linux
Elixir = Comfortable on Linux Mint
Recording and playback on Linux
Read core voltage on Linux
Put jenv on Amazon Linux
Easy df command on Linux
Linux on Windows -1-: debian introduction
Install tomcat 5.5 on Amazon Linux.
Introducing Elixir on Linux Mint
Use sshpass on Amazon linux2
Install Homebrew on Amazon Linux 2
Paste the link on linux
Install strongSwan 5.9.1 on Amazon Linux 2
Linux environment construction (on WSL environment)
Run FreeBSD on Linux + qemu
Use Linux on Windows 10 (WSL2)
Use host.docker.internal on linux (docker-compose required)
Install Python Pillow on Amazon Linux
Easy copy to clipboard on Linux
Install oracle java8 on amazon linux2
Try installing OpenAM on Amazon Linux
WSL2 ~ Linux on Windows ~ (Part 1: Introduction)
Install CUDA on Linux Mint Mate 20
Install Arch Linux on DeskMini A300
Completion of docker command on Linux
Run a Linux server on GCP
How to install VMware-Tools on Linux
View disk usage on personal Linux
Install pyenv on EC2 (Amazon Linux)
[Linux] I installed CentOS on VirtualBox
Turn Raspberry Pi into a router (Wake on LAN [4] over NAT)
Enjoy edge computing on Alpine Linux
Rip Music CDs on Arch Linux
Create a Linux environment on Windows 10
Make Live USB on Alpine Linux
Linux
[Linux] Docker environment construction on Redhat
Use Chrome Remote Desktop on Linux
[Note] Install Imagick on Amazon Linux2
[Note] Run Django on Amazon Linux 2
Run docker-compose on Amazon Linux2 on ARM64
Introduce Python 3.5.2 environment on Amazon Linux
pykintone on Windows Subsystem for Linux