Skip to content
Search

Net.ipv4.ip forward

lastmod 2025-12-16created 2023-11-077 edits

Determines whether this server can forward IP packets to other networks. When enabled (1), it can forward packets like a router. The default (0) only handles packets addressed to itself.

How to use a Linux server as a router

To set up direct communication over four Ethernet ports on a Linux server, you can follow the steps below. This configuration can be useful when the server handles multiple networks or must meet special network requirements.

First, check the network interfaces connected to the server. You can use the ifconfig command for this.

ifconfig

Check the list of interfaces and the name of each interface (e.g. eth0, eth1, eth2, eth3).

Now enable each Ethernet interface. For example, to enable each Ethernet interface, run the following.

sudo ifconfig eth0 up
sudo ifconfig eth1 up
sudo ifconfig eth2 up
sudo ifconfig eth3 up

The commands above enable each interface.

For direct communication, assign a unique IP address to each interface. These addresses must belong to different subnets. For example:

sudo ifconfig eth0 192.168.1.1 netmask 255.255.255.0
sudo ifconfig eth1 192.168.2.1 netmask 255.255.255.0
sudo ifconfig eth2 192.168.3.1 netmask 255.255.255.0
sudo ifconfig eth3 192.168.4.1 netmask 255.255.255.0

The commands above assign an IP address to each interface.

To allow communication between interfaces on different subnets, you need to set up routing. To do this, enable package forwarding and enable IP forwarding. Edit the /etc/sysctl.conf file and add the following line.

net.ipv4.ip_forward=1

Then apply the changes.

sudo sysctl -p

Why is it needed in Kubernetes?

  • Kubernetes nodes must relay traffic between Pods and between Pods and the outside
  • Container networks communicate through the host
  • Without this setting, Pods cannot communicate with the outside

How it works in practice

인터넷 <--> [K8s Node (라우터 역할)] <--> Pod 네트워크
                     ↑
            ip_forward=1이 필요한 지점

Problems if not set

  • Pods cannot access external networks
  • No cross-node communication between Pods
  • NAT does not work

See also

Favorite site

author Zer0 sitemap