AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / server / Perguntas / 1166245
Accepted
Thystra
Thystra
Asked: 2024-10-07 14:24:58 +0800 CST2024-10-07 14:24:58 +0800 CST 2024-10-07 14:24:58 +0800 CST

Acessando a internet do Strongswan / IKE2 VPN com nftables

  • 772

Tenho um servidor Ubuntu 24.04.1 LTS executando o Strongswan.

Desde então, descobri que ele está usando o nftables e não o iptables como firewall.

Ao configurar a VPN, consigo me conectar ao cliente, mas não consigo acessar hosts na Internet por endereço IP ou resolver nomes.

Acho que estou esquecendo algumas regras de encaminhamento, mas não tenho certeza de como traduzi-las/aplicá-las em um formato NFT.

Que regra(s) preciso aplicar para que o IPV4 e o IPV6 funcionem para os clientes?

A configuração abaixo começou com um guia wireguard e eu o modifiquei para incluir outros serviços que tenho na máquina. Encontrei algumas referências do openwrt e strongswan e tentei traduzir isso, mas acho que ainda não atingi o objetivo. Agradeço qualquer conselho.

Obrigado.

Adicionei-os numa tentativa de passar o tráfego ipsec

pré-roteamento de cadeia

 meta ipsec exists ip saddr $IKE_NETS counter accept

cadeia inbound_world


    meta l4proto ah accept
    meta l4proto esp accept

/etc/nftables.conf

#!/usr/sbin/nft -f

flush ruleset

define DEV_WG = wg0
define DEV_OVPN = tun0
define DEV_VPN = { $DEV_WG, $DEV_OVPN }
define DEV_WORLD = eth0
define IP_OVPN = 10.8.0.0/24
define IP_WORLD_V4 = public_v4_ip
define IP_WORLD_V6 = public_v6_ip
define PORT_IKE = { 500, 4500 }
define PORT_WG = 51820
define PORT_OVPN = 1194
define PORT_VPN = { $PORT_IKE, $PORT_WG, $PORT_OVPN  }
define DEV_LOCAL_NETS = { $DEV_VPN }
define DEV_OUT_NETS = { $DEV_WORLD }
#define IKE_NETS = { 172.16.252.0/24, fd5a:4c1f:8d73:f583::/64 } <- did not like the Ipv6 address
define IKE_NETS = { 172.16.252.0/24 }


# `inet` applies to both IPv4 and IPv6.
table inet global {
    map port_forwards_tcp_ipv4 {
        type ipv4_addr . inet_service : ipv4_addr . inet_service
        # lets forward port for our torrent. Our 12345 to 12345 on 172.16.0.2
        elements = { $IP_WORLD_V4 . 12345 : 172.16.0.2 . 12345 }
    }

    map port_forwards_tcp_ipv6 {
        type ipv6_addr . inet_service : ipv6_addr . inet_service
        # lets forward port for our torrent. Our 12345 to 12345 on fdf5:6028:947d:1234::2
        elements = { $IP_WORLD_V6 . 12345 : [fdf5:6028:947d:1234::2] . 12345}
    }

    map port_forwards_udp_ipv4 {
        type ipv4_addr . inet_service : ipv4_addr . inet_service
        # lets forward port for our torrent. Our 12345 to 12345 on 172.16.0.2
        elements = { $IP_WORLD_V4 . 12345 : 172.16.0.2 . 12345 }
    }

    map port_forwards_udp_ipv6 {
        type ipv6_addr . inet_service : ipv6_addr . inet_service
        # lets forward port for our torrent. Our 12345 to 12345 on fdf5:6028:947d:1234::2
        elements = { $IP_WORLD_V6 . 12345 : [fdf5:6028:947d:1234::2] . 12345}
    }

    chain inbound_world {
        # accepting ping (icmp-echo-request) for diagnostic purposes.
        # However, it also lets probes discover this host is alive.
        # This sample accepts them within a certain rate limit:
        #
        # icmp type echo-request limit rate 5/second accept

        # Allow IPv6 configuration packets
        icmpv6 type {nd-neighbor-solicit,nd-neighbor-advert,nd-router-solicit, 
             nd-router-advert,mld-listener-query,destination-unreachable,
             packet-too-big,time-exceeded,parameter-problem} accept

        # allow SSH
        tcp dport { 22 } accept

        # http, https
        tcp dport 80 accept
        tcp dport 443 accept

        # smtp, submission, smtps
        tcp dport 25 accept
        tcp dport 587 accept
        tcp dport 465 accept

        # pop3, pop3s
        tcp dport 110 accept
        tcp dport 995 accept

        # imap, imaps
        tcp dport 143 accept
        tcp dport 993 accept

       # allow VPN connection
    udp dport { $PORT_VPN } accept

    meta l4proto ah accept
    meta l4proto esp accept
    }

    chain inbound_vpn {
        # accepting ping (icmp-echo-request) for diagnostic purposes.
        icmp type echo-request limit rate 5/second accept

        # Allow IPv6 configuration packets
        icmpv6 type {nd-neighbor-solicit,nd-neighbor-advert,nd-router-solicit,
             nd-router-advert,mld-listener-query,destination-unreachable,
             packet-too-big,time-exceeded,parameter-problem} accept

        # allow DNS and SSH from the private network
        tcp dport { 22, 53 } accept
        udp dport { 53 } accept
    }

    chain inbound {
        # drop all traffic by default
        type filter hook input priority filter; policy drop;

        # Allow traffic from established and related packets, drop invalid
        ct state vmap { established : accept, related : accept, invalid : drop }
        # Allow dnat (port forwarding)
        ct status dnat accept

        # allow loopback traffic, anything else jump to chain for further evaluation
        iifname vmap { lo : accept, $DEV_WORLD : jump inbound_world, $DEV_VPN : jump inbound_vpn}

        # the rest is dropped by the above policy
    }

    chain forward {
        type filter hook forward priority filter; policy drop;

        # Allow traffic from established and related packets, drop invalid
        ct state vmap { established : accept, related : accept, invalid : drop }
        # Allow port forwarding
        ct status dnat accept

        # connections from the internal nets to the out nets are allowed
        iifname $DEV_LOCAL_NETS oifname $DEV_OUT_NETS accept
        # the rest is dropped by the above policy
        meta ipsec exists ip saddr $IKE_NETS counter accept


    }

    chain prerouting {
       type nat hook prerouting priority dstnat; policy accept;
       dnat ip addr . port to ip daddr . tcp dport map @port_forwards_tcp_ipv4
       dnat ip6 addr . port to ip6 daddr . tcp dport map @port_forwards_tcp_ipv6
       dnat ip addr . port to ip daddr . udp dport map @port_forwards_udp_ipv4
       dnat ip6 addr . port to ip6 daddr . udp dport map @port_forwards_udp_ipv6
       meta ipsec exists ip saddr $IKE_NETS counter accept
    }

    chain postrouting {
        type nat hook postrouting priority srcnat; policy accept;
        # Hide IPs from local nets to the internet.
        # We are using SNAT because we have static IP and it wil work faster than MASQUERADE
        iifname $DEV_LOCAL_NETS oifname $DEV_WORLD snat ip to $IP_WORLD_V4
        iifname $DEV_LOCAL_NETS oifname $DEV_WORLD snat ip6 to $IP_WORLD_V6
    }
}

Piscinas Strongswan:

pools {
    primary-pool-ipv4 {
        addrs = 172.16.252.0/24
        dns = 172.16.252.1, 8.8.8.8, 9.9.9.9
        split_exclude = 172.16.0.0/12
    }
    primary-pool-ipv6 {
        addrs = fd5a:4c1f:8d73:f583::/64
    dns = 2620:fe::fe, 2620:fe::9

    }
ubuntu
  • 1 1 respostas
  • 24 Views

1 respostas

  • Voted
  1. Best Answer
    Thystra
    2024-10-09T09:18:24+08:002024-10-09T09:18:24+08:00

    Implementação funcional no meu servidor para IPSEC e outras VPNs.

    #!/usr/sbin/nft -f
    #to reload: nft -f /etc/nftables.conf
    flush ruleset
    
    define DEV_WG = wg0
    define DEV_OVPN = tun0
    define DEV_VPN = { $DEV_WG, $DEV_OVPN }
    define DEV_WORLD = eth0
    define IP_OVPN = 10.8.0.0/24
    define IP_WORLD_V4 = YOURIP4ADDRESS
    define IP_WORLD_V6 = YOURIP6ADDRESS
    define PORT_IKE = { 500, 4500 }
    define PORT_WG = 51820
    define PORT_OVPN = 1194
    define PORT_VPN = { $PORT_IKE, $PORT_WG, $PORT_OVPN  }
    define DEV_LOCAL_NETS = { $DEV_VPN }
    define DEV_OUT_NETS = { $DEV_WORLD }
    define IKE_NET6 = { fd5a:4c1f:8d73:f583::/64 }
    define IKE_NETS = { 172.16.252.0/24 }
    
    
    
    # `inet` applies to both IPv4 and IPv6.
    table inet global {
        map port_forwards_tcp_ipv4 {
            type ipv4_addr . inet_service : ipv4_addr . inet_service
            # lets forward port for our torrent. Our 12345 to 12345 on 172.16.0.2
            elements = { $IP_WORLD_V4 . 12345 : 172.16.0.2 . 12345 }
        }
    
        map port_forwards_tcp_ipv6 {
            type ipv6_addr . inet_service : ipv6_addr . inet_service
            # lets forward port for our torrent. Our 12345 to 12345 on fdf5:6028:947d:1234::2
            elements = { $IP_WORLD_V6 . 12345 : [fdf5:6028:947d:1234::2] . 12345}
        }
    
        map port_forwards_udp_ipv4 {
            type ipv4_addr . inet_service : ipv4_addr . inet_service
            # lets forward port for our torrent. Our 12345 to 12345 on 172.16.0.2
            elements = { $IP_WORLD_V4 . 12345 : 172.16.0.2 . 12345 }
        }
    
        map port_forwards_udp_ipv6 {
            type ipv6_addr . inet_service : ipv6_addr . inet_service
            # lets forward port for our torrent. Our 12345 to 12345 on fdf5:6028:947d:1234::2
            elements = { $IP_WORLD_V6 . 12345 : [fdf5:6028:947d:1234::2] . 12345}
        }
    
        chain inbound_world {
            # accepting ping (icmp-echo-request) for diagnostic purposes.
            # However, it also lets probes discover this host is alive.
            # This sample accepts them within a certain rate limit:
            #
            # icmp type echo-request limit rate 5/second accept
    
            # Allow IPv6 configuration packets
            icmpv6 type {nd-neighbor-solicit,nd-neighbor-advert,nd-router-solicit,
                 nd-router-advert,mld-listener-query,destination-unreachable,
                 packet-too-big,time-exceeded,parameter-problem} accept
    
            # allow SSH
            tcp dport { 22 } accept
    
            # http, https
            tcp dport 80 accept
            tcp dport 443 accept
    
            # smtp, submission, smtps
            tcp dport 25 accept
            tcp dport 587 accept
            tcp dport 465 accept
    
            # pop3, pop3s
            tcp dport 110 accept
            tcp dport 995 accept
    
            # imap, imaps
            tcp dport 143 accept
            tcp dport 993 accept
    
           # allow VPN connection
        udp dport { $PORT_VPN } accept
    
        meta l4proto ah  counter accept comment "AH accept"
        meta l4proto esp  counter accept  comment "ESP Accept"
        }
    
        chain inbound_vpn {
            # accepting ping (icmp-echo-request) for diagnostic purposes.
            icmp type echo-request limit rate 5/second accept
    
            # Allow IPv6 configuration packets
            icmpv6 type {nd-neighbor-solicit,nd-neighbor-advert,nd-router-solicit,
                 nd-router-advert,mld-listener-query,destination-unreachable,
                 packet-too-big,time-exceeded,parameter-problem} accept
    
            # allow DNS and SSH from the private network
            tcp dport { 22, 53 } accept
            udp dport { 53 } accept
        }
    
        chain inbound {
            # drop all traffic by default
            type filter hook input priority filter; policy drop;
    
            # Allow traffic from established and related packets, drop invalid
            ct state vmap { established : accept, related : accept, invalid : drop }
            # Allow dnat (port forwarding)
            ct status dnat accept
    
            # allow loopback traffic, anything else jump to chain for further evaluation
            iifname vmap { lo : accept, $DEV_WORLD : jump inbound_world, $DEV_VPN : jump inbound_vpn}
    
            # Allow VPN clients to communicate with each other.
            # iifname $DEV_VPN oifname $DEV_VPN ct state new accept
    
            # the rest is dropped by the above policy
        }
    
        chain forward {
            type filter hook forward priority filter; policy drop;
    
            # Allow traffic from established and related packets, drop invalid
            ct state vmap { established : accept, related : accept, invalid : drop }
            # Allow port forwarding
            ct status dnat accept
    
            # connections from the internal nets to the out nets are allowed
            iifname $DEV_LOCAL_NETS oifname $DEV_OUT_NETS accept
            # the rest is dropped by the above policy
    
        #ipsec vpn config
            meta ipsec exists ip saddr $IKE_NETS counter accept comment "forward ipsec"
            meta ipsec exists ip6 saddr $IKE_NET6 counter accept comment "forward ipsec v6"
    
    
        }
    
        chain prerouting {
           type nat hook prerouting priority dstnat; policy accept;
           dnat ip addr . port to ip daddr . tcp dport map @port_forwards_tcp_ipv4
           dnat ip6 addr . port to ip6 daddr . tcp dport map @port_forwards_tcp_ipv6
           dnat ip addr . port to ip daddr . udp dport map @port_forwards_udp_ipv4
           dnat ip6 addr . port to ip6 daddr . udp dport map @port_forwards_udp_ipv6
    
        #ipsec vpn config?
           meta ipsec exists ip saddr $IKE_NETS counter accept comment "prerouting ipsec v4"
           meta ipsec exists ip6 saddr $IKE_NET6 counter accept comment "prerouting ipsec v6"
    
        }
    
        chain postrouting {
            type nat hook postrouting priority srcnat; policy accept;
            # Hide IPs from local nets to the internet.
            # We are using SNAT because we have static IP and it wil work faster than MASQUERADE
            ip saddr $IKE_NETS oifname $DEV_WORLD counter snat ip to $IP_WORLD_V4 comment "postrouting ipsec v4"
            ip6 saddr $IKE_NET6 oifname $DEV_WORLD counter snat ip6 to $IP_WORLD_V6 comment "postrouting ipsec v6"
    
            iifname $DEV_LOCAL_NETS oifname $DEV_WORLD snat ip to $IP_WORLD_V4
            iifname $DEV_LOCAL_NETS oifname $DEV_WORLD snat ip6 to $IP_WORLD_V6
        }
    
    #End of Table
    }
    
    • 0

relate perguntas

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Você pode passar usuário/passar para autenticação básica HTTP em parâmetros de URL?

    • 5 respostas
  • Marko Smith

    Ping uma porta específica

    • 18 respostas
  • Marko Smith

    Verifique se a porta está aberta ou fechada em um servidor Linux?

    • 7 respostas
  • Marko Smith

    Como automatizar o login SSH com senha?

    • 10 respostas
  • Marko Smith

    Como posso dizer ao Git para Windows onde encontrar minha chave RSA privada?

    • 30 respostas
  • Marko Smith

    Qual é o nome de usuário/senha de superusuário padrão para postgres após uma nova instalação?

    • 5 respostas
  • Marko Smith

    Qual porta o SFTP usa?

    • 6 respostas
  • Marko Smith

    Linha de comando para listar usuários em um grupo do Windows Active Directory?

    • 9 respostas
  • Marko Smith

    O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL?

    • 3 respostas
  • Marko Smith

    Como determinar se uma variável bash está vazia?

    • 15 respostas
  • Martin Hope
    Davie Ping uma porta específica 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    kernel O scp pode copiar diretórios recursivamente? 2011-04-29 20:24:45 +0800 CST
  • Martin Hope
    Robert ssh retorna "Proprietário incorreto ou permissões em ~/.ssh/config" 2011-03-30 10:15:48 +0800 CST
  • Martin Hope
    Eonil Como automatizar o login SSH com senha? 2011-03-02 03:07:12 +0800 CST
  • Martin Hope
    gunwin Como lidar com um servidor comprometido? 2011-01-03 13:31:27 +0800 CST
  • Martin Hope
    Tom Feiner Como posso classificar a saída du -h por tamanho 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent Como determinar se uma variável bash está vazia? 2009-05-13 09:54:48 +0800 CST

Hot tag

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve