Article Title: how to set up Ubuntu as a gateway. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Hardware Requirements:
A pc with Ubuntu installed.
Two NICs.
The configuration is simple. suppose there are two network segments: 0 and 1, 192.168.0.0 and 192.168.1.0, respectively. Eth0 is connected to network No. 0, and eth1 is connected to network No. 1. Now, the two NICs, eth0 and eth1, are assigned IP addresses of different network segments:
# Sudo ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up
# Sudo ifconfig eth1 192.168.1.1 netmask 255.255.255.0 up better configuration from the interface management, so that the above command is not executed every time.
Enable iptables forwarding rules:
# Echo 1> the default ip_forward value of proc/sys/net/ipv4/ip_forward is zero. forwarding is not allowed. you can simply change it to 1. If you want to allow forwarding at startup, add the preceding command to the startup script rc. local.
Configure the computers in network No. 0 and network No. 1. the gateways are 192.168.0.0 and 192.168.1.0 respectively. In this way, the computer in the network segment 0 can access the computer in the network segment 1, and the computer in the network segment 1 can also access the computer in the network segment 0.