Meu objetivo é configurar um namespace separado no meu servidor Linux que eu possa usar para uma conexão OpenVPN e, em seguida, um host VirtualBox.
Até agora segui estes passos:
- Configurar um cronjob
@reboot /home/ubuntu/startupscripts/rootscripts.sh
- Dentro do script de shell, execute: (Adaptado daqui)
# Setup VPN
ip netns add vpnspace
ip link add vpnopen type veth peer name vpnbind
ip link set vpnopen netns vpnspace
ip netns exec vpnspace /sbin/ifconfig vpnopen 10.0.0.1/24 up
(Veja a pergunta)
/sbin/ifconfig vpnbind up
**
- Adicionadas as regras iptables abaixo e reconfiguradas iptables-persistent (Adaptado de) < href="https://serverfault.com/questions/897710/iptables-rules-dissappear-when-manually-adding-a-nat-rule-to-iptables-persistent"> (ver pergunta) % código%
** Eu adicionei esta etapa porque
-A FORWARD -i vpnbind -o ens3 -j ACCEPT
-A FORWARD -i ens3 -o vpnbind -m state --state ESTABLISHED,RELATED -j ACCEPT
-t nat -A POSTROUTING -o eth0 -j MASQUERADE
mostrou que a conexão de rede não estava ativa. (Veja a pergunta)
Quando eu tento sudo lshw -C network
do terminal, recebo a mensagem de erro sudo ip netns exec vpnspace ping 8.8.8.8
. Não tenho certeza para onde ir a partir daqui.
Abaixo estão várias saídas. Por favor, diga nos comentários se você gostaria que eu adicionasse outros.
ifconfig :
ens3 Link encap:Ethernet HWaddr XX:XX:XX:XX:XX:XX
inet addr:XXX.XXX.XXX.92 Bcast:XXX.225.222.255 Mask:255.255.255.0
inet6 addr: XXXX::XXXX:XXXX:XXXX:XXXX/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:44943 errors:16 dropped:0 overruns:0 frame:16
TX packets:467 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3042544 (3.0 MB) TX bytes:49351 (49.3 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:100 (100.0 B) TX bytes:100 (100.0 B)
vpnbind Link encap:Ethernet HWaddr XX:XX:XX:XX:XX:XX
inet6 addr: XXXX::XXXX:XXXX:XXXX:XXXX/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:648 (648.0 B) TX bytes:0 (0.0 B)
sudo ip netns exec vpnspace ifconfig :
vpnopen Link encap:Ethernet HWaddr 36:28:6f:74:1b:72
inet addr:10.0.0.1 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: XXXX::XXXX:XXXX:XXXX:XXXX/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:648 (648.0 B)
ip link show :
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff
3: vpnbind@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff link-netnsid 0
sudo ip netns exec vpnspace ip link show :
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
4: vpnopen@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff link-netnsid 0
/ etc / network / interfaces :
# The loopback network interface
auto lo
iface lo inet loopback
# Preconfigured by my VPS provider
auto ens3
iface ens3 inet static
address XXX.XXX.XXX.92
netmask 255.255.255.0
broadcast +
up route -A inet add XXX.XXX.XXX.1 dev ens3
up route -A inet add default gw XXX.XXX.XXX.1 dev ens3
iface ens3 inet6 manual
pre-down ip -6 addr flush dev ens3 scope global || :
Script atualizado
ip netns add vpnspace
ip link add vpnopen type veth peer name vpnbind
echo 1 > /proc/sys/net/ipv4/conf/ens3/forwarding
echo 1 > /proc/sys/net/ipv4/conf/vpnbind/forwarding
ip link set vpnbind up
ip link set vpnopen netns vpnspace
ip -n vpnspace addr add 10.0.0.1 dev vpnopen
ip -n vpnspace addr add 10.0.0.254 broadcast 10.0.0.255 dev vpnopen
ip -n vpnspace link set vpnopen up
ip -n vpnspace route add default via 10.0.0.254