I want to configure my Linux so that it will be used as a network router (gateway). Can anybody give me some hints on this? (links are welcome!)
For a simple router, there are really only two steps that need to be done.
The first step is to enable routing in the kernel. By default, the kernel drops packets that it doesn't recognize; once you enable routing, it'll forward them. You need to issue either of these two commands when the computer boots:
sysctl -w net.ipv4.ip_forward=1 echo 1 >/proc/sys/net/ipv4/ip_forward
Many distributions have a file called
/etc/sysctl.conf, where you can put the line
net.ipv4.ip_forward=1 to execute that command when the computer boots. If there's a directory
/etc/sysctl.d, you can add a file in that directory instead of editing
/etc/sysctl.conf; call the file
For IPv6, the corresponding setting is
/proc/sys/net/ipv6/conf/all/forwarding. You can also use
/proc/sys/net/ipv4/conf/all/forwarding for IPv4.
Set routing tables
The second step is to set routing tables. This can be simple or complicated depending on how much you need to do. For simple uses, configure each of your network interfaces' address and netmask, and add any needed extra route with the
Going beyond simple routing
If you need to rewrite packets, the basic command is
ip6tables for IPv6). (“Netfilter” is the name of the kernel packet handling facility, and “iptables” if the name of the program that controls it.) This is where to look for filtering, NAT and more.
For complex setups, look at the
ip command from the iproute2 package.
First plug in the IPs of the network for which you want to act as router. Either get multiple network interface cards or configure a virtual interface.
You need to enable packet forwarding from
/etc/sysctl.conf and then configure iptables for NAT. Here is a brief tutorial for the same.