Linux Networking: Difference between revisions
Jump to navigation
Jump to search
(Added IPv4 forwarding and NAT) |
m (→Set default IPv6 gateway: Added missing words) |
||
| Line 14: | Line 14: | ||
== Set default IPv6 gateway == | == Set default IPv6 gateway == | ||
ip -6 r a ''gateway'' dev ''iface'' | ip -6 r a default via ''gateway'' dev ''iface'' | ||
== IPv4 forwarding and NAT == | == IPv4 forwarding and NAT == | ||
Latest revision as of 12:47, 8 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 default via gateway dev iface
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".