Linux Networking: Difference between revisions
Jump to navigation
Jump to search
(Initial creation: add address, gateway, forwarding) |
(Added IPv4 forwarding and NAT) |
||
| Line 17: | Line 17: | ||
''gateway'' '''must not''' be a link local address (that is one that starts with "fe80")! | ''gateway'' '''must not''' be a link local address (that is one that starts with "fe80")! | ||
== IPv4 forwarding and NAT == | |||
Check if IPv4 forwarding is activated: | |||
sysctl net.ipv4.conf.all.forwarding | |||
On demand run | |||
sysctl -w net.ipv4.conf.all.forwarding=1 | |||
Perform NAT on the interface that has Internet connection using iptables: | |||
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | |||
== IPv6 forwarding == | == IPv6 forwarding == | ||
Revision as of 06:08, 2 June 2026
Some important commands and settings that are needed frequently.
Add IPv4/IPv6 address to interface
In the past, ifconfig was used to add ip addresses. Nowadays, the ip command is used instead.
ip [-6] a a address dev iface
Examples:
ip a a 10.0.0.1 dev enp2s0 ip -6 a a fd40:cafe:affe:1234::1 dev enp0s3
Set default IPv6 gateway
ip -6 r a gateway dev iface
gateway must not be a link local address (that is one that starts with "fe80")!
IPv4 forwarding and NAT
Check if IPv4 forwarding is activated:
sysctl net.ipv4.conf.all.forwarding
On demand run
sysctl -w net.ipv4.conf.all.forwarding=1
Perform NAT on the interface that has Internet connection using iptables:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
IPv6 forwarding
Query:
sysctl net.ipv6.conf.all.forwarding
Or using procfs:
cat /proc/sys/net/ipv6/conf/all/forwarding
Activating:
sysctl -w net.ipv6.conf.all.forwarding=1
Remark: "all" can be substituted by any network interface on the system, for example, cat /proc/sys/net/ipv6/conf/eth0/forwarding prints the value for interface "eth0".