This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| tips:linux:networknamespaces [2019/01/24 15:30] – created scipio | tips:linux:networknamespaces [2019/01/24 19:03] (current) – [use] scipio | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| ===== setup ===== | ===== setup ===== | ||
| - | install [[netns|https:// | + | install [[https:// |
| - | {{{ | + | < |
| wget https:// | wget https:// | ||
| chmod +x /bin/nets | chmod +x /bin/nets | ||
| - | }}} | + | </ |
| uncomment " | uncomment " | ||
| enable NAT | enable NAT | ||
| - | {{{ | + | < |
| iptables -t nat -A POSTROUTING -o ens3 -j MASQUERADE | iptables -t nat -A POSTROUTING -o ens3 -j MASQUERADE | ||
| iptables-save | iptables-save | ||
| - | }}} | + | </ |
| - | }}} | + | bash prompt, add to .bashrc |
| + | < | ||
| + | _ns_name=$(ip netns identify 2>/ | ||
| + | PS1=${_ns_name: | ||
| + | unset _ns_name | ||
| + | </ | ||
| + | |||
| + | ===== use ===== | ||
| + | |||
| + | create namespace " | ||
| + | < | ||
| + | netns 0 start | ||
| + | </ | ||
| + | |||
| + | run bach inside | ||
| + | < | ||
| + | netns 0 exec | ||
| + | </ | ||
| + | |||
| + | permit routing | ||
| + | < | ||
| + | ip netns exec netns0 sysctl -w net.ipv4.ip_forward=1 | ||
| + | iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE | ||
| + | </ | ||
| + | |||
| + | |||
| + | inside NS | ||
| + | < | ||
| + | iptables -t nat -A PREROUTING -d 10.9.0.2 -p tcp --dport 443 -j DNAT --to-destination 10.139.231.1: | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | curl -k --header "Host: www.xxx.it" | ||
| + | </ | ||