Score:0

Router [ER-X] as WireGuard Client to hide Office IP on Debian Server. Cannot bind to WireGuard IP from the server

de flag

Dear ServerFault community

I have a problem with my WireGuard Tunnel overall configuration.

I have an OVH VPS with 4 public IPs (MY_PUBLIC) acting as a WireGuard server and forwarding all the traffic (and ports) to my EdgeRouter-X router (192.168.255.1) (which acts as a WireGuard client) and that, then, forwards it to my Debian server (192.168.255.10).

The problem is that when on the Debian server I try to bind to any of the OVH VPS WireGuard's public IPs (MY_PUBLIC) [I tried making Apache bind to them, along with MariaDB and Docker but nothing] I get a bind error telling me that it is not possible.

 bind: cannot assign requested address.

After some research I found this:

The message “Cannot assign requested address” suggests that the hostname/IP you are trying to bind does not resolve to a local network interface.

From online research this seems to suggest a NAT being somewhere between the VPS and the server. I am a newbie with networks and I have no idea how to solve this issue.

This is a major issue as the server can only use those IPs binding to 0.0.0.0.

My ER-X configuration:

firewall {
    all-ping enable
    broadcast-ping disable
    group {
        address-group MY_PUBLIC { // OVH VPS's IPs
            address 92.CENSORED.CENSORED.108
            address 149.CENSORED.CENSORED.64
            address 37.CENSORED.CENSORED.244
            address 149.CENSORED.CENSORED.244
        }
    }
    ipv6-name WANv6_IN {
        default-action drop
        description "WAN inbound traffic forwarded to LAN"
        enable-default-log
        rule 10 {
            action accept
            description "Allow established/related sessions"
            state {
                established enable
                related enable
            }
        }
        rule 20 {
            action drop
            description "Drop invalid state"
            state {
                invalid enable
            }
        }
    }
    ipv6-name WANv6_LOCAL {
        default-action drop
        description "WAN inbound traffic to the router"
        enable-default-log
        rule 10 {
            action accept
            description "Allow established/related sessions"
            state {
                established enable
                related enable
            }
        }
        rule 20 {
            action drop
            description "Drop invalid state"
            state {
                invalid enable
            }
        }
        rule 30 {
            action accept
            description "Allow IPv6 icmp"
            protocol ipv6-icmp
        }
        rule 40 {
            action accept
            description "allow dhcpv6"
            destination {
                port 546
            }
            protocol udp
            source {
                port 547
            }
        }
    }
    ipv6-receive-redirects disable
    ipv6-src-route disable
    ip-src-route disable
    log-martians enable
    modify wireguard_route {
        rule 5 {
            action modify
            destination {
                group {
                    address-group MY_PUBLIC
                }
            }
            modify {
                table main
            }
        }
        rule 7 {
            action modify
            destination {
                address 172.16.1.0/24
            }
            modify {
                table main
            }
        }
        rule 10 {
            action modify
            description wireguard-vpn
            modify {
                table 1
            }
            source {
                address 192.168.255.0/24
            }
        }
    }
    name WAN_IN {
        default-action drop
        description "WAN to internal"
        rule 10 {
            action accept
            description "Allow established/related"
            state {
                established enable
                related enable
            }
        }
        rule 20 {
            action drop
            description "Drop invalid state"
            state {
                invalid enable
            }
        }
    }
    name WAN_LOCAL {
        default-action drop
        description "WAN to router"
        rule 10 {
            action accept
            description "Allow established/related"
            state {
                established enable
                related enable
            }
        }
        rule 20 {
            action drop
            description "Drop invalid state"
            state {
                invalid enable
            }
        }
        rule 30 {
            action accept
            description openvpn
            destination {
                port 1194
            }
            protocol udp
        }
    }
    receive-redirects disable
    send-redirects enable
    source-validation disable
    syn-cookies enable
}
interfaces {
    ethernet eth0 {
        address dhcp
        description Internet
        dhcpv6-pd {
            pd 0 {
                interface eth1 {
                    service dhcpv6-stateful
                }
                interface eth2 {
                    service dhcpv6-stateful
                }
                interface eth3 {
                    service dhcpv6-stateful
                }
                interface switch0 {
                    host-address ::1
                    service slaac
                }
                prefix-length /64
            }
            rapid-commit enable
        }
        duplex auto
        firewall {
            in {
                ipv6-name WANv6_IN
                name WAN_IN
            }
            local {
                ipv6-name WANv6_LOCAL
                name WAN_LOCAL
            }
        }
        ipv6 {
            address {
                autoconf
            }
            dup-addr-detect-transmits 1
        }
        speed auto
    }
    ethernet eth1 {
        description Local
        duplex auto
        speed auto
    }
    ethernet eth2 {
        description Local
        duplex auto
        speed auto
    }
    ethernet eth3 {
        description Local
        duplex auto
        speed auto
    }
    ethernet eth4 {
        description Local
        duplex auto
        poe {
            output off
        }
        speed auto
    }
    loopback lo {
    }
    openvpn vtun0 {
        mode server
        server {
            name-server 192.168.255.1
            push-route 192.168.255.0/24
            subnet 172.16.1.0/24
        }
        tls {
            ca-cert-file /config/auth/cacert.pem
            cert-file /config/auth/server.pem
            dh-file /config/auth/dh.pem
            key-file /config/auth/server.key
        }
    }
    switch switch0 {
        address 192.168.255.1/24
        description Local
        firewall {
            in {
                modify wireguard_route
            }
        }
        mtu 1500
        switch-port {
            interface eth1 {
            }
            interface eth2 {
            }
            interface eth3 {
            }
            interface eth4 {
            }
            vlan-aware disable
        }
    }
    wireguard wg0 {
        address 10.0.0.2/30
        description Wireguard
        listen-port 51821
        mtu 1420
        peer CENSORED+CENSORED+CENSORED= {
            allowed-ips 0.0.0.0/0
            endpoint 92.CENSORED.CENSORED.108:51821
            persistent-keepalive 25
            preshared-key /config/auth/wg-preshared.key
        }
        private-key /config/auth/wg.key
        route-allowed-ips false
    }
}
port-forward {
    auto-firewall enable
    hairpin-nat enable
    lan-interface switch0
    rule 1 {
        description "Allow ALL"
        forward-to {
            address 192.168.255.10
        }
        original-port 1-65535
        protocol tcp_udp
    }
    wan-interface wg0
}
protocols {
    static {
        table 1 {
            description "table to force wg0:aws"
            interface-route 0.0.0.0/0 {
                next-hop-interface wg0 {
                }
            }
            route 0.0.0.0/0 {
                blackhole {
                    distance 255
                }
            }
        }
    }
}
service {
    dhcp-server {
        disabled false
        hostfile-update disable
        shared-network-name LAN-X {
            authoritative disable
            subnet 192.168.255.0/24 {
                default-router 192.168.255.1
                dns-server 192.168.255.1
                lease 86400
                start 192.168.255.2 {
                    stop 192.168.255.254
                }
                static-mapping iDRAC {
                    ip-address 192.168.255.120
                    mac-address CENSORED:CENSORED:CENSORED:CENSORED:CENSORED:CENSORED
                }
                static-mapping node2 {
                    ip-address 192.168.255.10
                    mac-address CENSORED:CENSORED:CENSORED:CENSORED:CENSORED:CENSORED
                }
            }
        }
        static-arp disable
        use-dnsmasq disable
    }
    dns {
        forwarding {
            cache-size 150
            listen-on switch0
            listen-on vtun0
        }
    }
    gui {
        http-port 80
        https-port 443
        older-ciphers enable
    }
    nat {
        rule 5001 {
            description wireguard-nat
            log disable
            outbound-interface wg0
            protocol all
            source {
                address 192.168.255.0/24
            }
            type masquerade
        }
        rule 5002 {
            description "masquerade for WAN"
            log disable
            outbound-interface eth0
            protocol all
            type masquerade
        }
    }
    ssh {
        port 22
        protocol-version v2
    }
    unms {
    }
}
system {
    analytics-handler {
        send-analytics-report false
    }
    crash-handler {
        send-crash-report false
    }
    host-name EdgeRouter-X-5-Port
    login {
        user ubnt {
            authentication {
                encrypted-password CENSORED
            }
            level admin
        }
    }
    ntp {
        server 0.ubnt.pool.ntp.org {
        }
        server 1.ubnt.pool.ntp.org {
        }
        server 2.ubnt.pool.ntp.org {
        }
        server 3.ubnt.pool.ntp.org {
        }
    }
    offload {
        hwnat enable
        ipsec enable
    }
    syslog {
        global {
            facility all {
                level notice
            }
            facility protocols {
                level debug
            }
        }
    }
    time-zone UTC
}

My OVH VPS's WG config:

[Interface]
Address = 10.0.0.1/30
ListenPort = 51821
PrivateKey = CENSORED

### Client vpn
[Peer]
PublicKey = CENSORED
PresharedKey = CENSORED
AllowedIPs = 10.0.0.2/30

My OVH IPTables:

# Generated by iptables-save v1.8.7 on Sun Jan  9 11:04:33 2022

*filter

:INPUT ACCEPT [971:145912]

:FORWARD ACCEPT [920:137172]

:OUTPUT ACCEPT [637:108812]

:f2b-sshd - [0:0]

COMMIT

# Completed on Sun Jan  9 11:04:33 2022

# Generated by iptables-save v1.8.7 on Sun Jan  9 11:04:33 2022

*nat

:PREROUTING ACCEPT [133:6792]

:INPUT ACCEPT [61:2272]

:OUTPUT ACCEPT [3:228]

:POSTROUTING ACCEPT [66:4011]

-A PREROUTING -i ens3 -p udp -m multiport --dports 1000:51820 -j DNAT --to-destination 10.0.0.2

-A PREROUTING -i ens3 -p udp -m multiport --dports 51822:65534 -j DNAT --to-destination 10.0.0.2

-A PREROUTING -i ens3 -p tcp -m multiport --dports 51822:65534 -j DNAT --to-destination 10.0.0.2

-A PREROUTING -i ens3 -p tcp -m multiport --dports 1000:51820 -j DNAT --to-destination 10.0.0.2

-A PREROUTING -i ens3 -p tcp -m multiport --dports 21,22,80,25,995,110,443,465,993,143 -j DNAT --to-destination 10.0.0.2

-A PREROUTING -i ens3 -p udp -m multiport --dports 21,22,80,25,995,110,443,465,993,143 -j DNAT --to-destination 10.0.0.2

-A POSTROUTING -o ens3 -j MASQUERADE

COMMIT

# Completed on Sun Jan  9 11:04:33 2022

Just for troubleshooting I tried binding to my Office IP which, as expected and wanted, does not work as behind ER-X's WireGuard Tunnel.

Here are some topics that helped me set my current WireGuard structure UP: https://community.ui.com/questions/EdgeRouter-X-as-WireGuard-Client-Forward-ports-from-WG-tunnel-to-LAN/f19957fb-70be-485f-832d-381c6ea4b306

https://community.ui.com/questions/EdgeRouter-X-as-a-WireGuard-client-with-port-forwarding-or-User-IP-is-shown-to-be-WireGuard-tunnels/2a8b19ab-ac0c-48ed-b367-afd3914de9c2

Thank you in advance for your help!

djdomi avatar
za flag
you should consider to use a reverse proxy to route the http traffic
Nicolò avatar
de flag
@djdomi The problem is that I need all ports to be forwarded and bindable, for example by Docker.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.