Sign inSign up

draz1c/openvpn-client

By draz1c

Updated about 2 years ago

Image
Networking
0

118

draz1c/openvpn-client repository overview

Contains:

Dockerfile
entrypoint.sh
client.conf
docker-compose.yml
Dockerfile
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y openvpn iptables iptables-persistent curl iputils-ping

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
entrypoint.sh
#!/bin/bash

# Habilitar el reenvío de IPv4
echo 1 > /proc/sys/net/ipv4/ip_forward

# Reglas IPtables:

# Habilitar NAT en la interfaz tun0 (de OpenVPN)
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE

# Permitir el tráfico que va desde la red interna (eth0) a través del túnel (tun0)
iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT

# Permitir el tráfico que regresa desde el túnel (tun0) hacia la red interna (eth0)
iptables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT

# Permitir tráfico loopback (interfaz lo)
iptables -A INPUT -i lo -j ACCEPT

# Permitir a los dispositivos de la red local hacer ping al host (Raspberry Pi)
iptables -A INPUT -i eth0 -p icmp -j ACCEPT

# Permitir conexiones SSH desde la red interna
iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT

# Permitir todo el tráfico iniciado por el host (máquina contenedora) para que pueda regresar
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# Establecer la política predeterminada para las cadenas INPUT y FORWARD a DROP
iptables -P INPUT DROP
iptables -P FORWARD DROP

# Iniciar OpenVPN
openvpn --config /etc/openvpn/client.conf
To make it work (the easier way) it needs a MACvlan in Docker:
docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=eth0 macvlan_openvpn_net
Sample docker-compose file
services:
    openvpn-client:
        container_name: openvpn-client
        cap_add:
            - NET_ADMIN
        devices:
            - /dev/net/tun
        privileged: true
        image: draz1c/openvpn-client
        restart: unless-stopped
        volumes:
          - './client.conf:/etc/openvpn/client.conf'
        networks:
          macvlan_openvpn_net:
            ipv4_address: 192.168.1.41

networks:
  macvlan_openvpn_net:
    external: true

Tag summary

Content type

Image

Digest

sha256:a2696d281

Size

66.3 MB

Last updated

about 2 years ago

docker pull draz1c/openvpn-client