Unable to set up wireguard interface


I configured wireguard in /etc/config/firewall and /etc/config/network using the following script file.


# Install packages
opkg update
opkg install wireguard luci-proto-wireguard luci-app-wireguard
# Configuration parameters

# Generate and exchange the keys
mkdir -p /etc/wireguard
chmod 700 /etc/wireguard
cd /etc/wireguard

umask u=rw,g=,o=
wg genkey | tee wgserver.key | wg pubkey > wgserver.pub
wg genpsk > wg.psk
WG_KEY="$(cat wgserver.key)"
WG_PSK="$(cat wg.psk)"
WG_PUB="$(cat wgserver.pub)"

# Configure firewall
uci rename firewall.@zone[0]="lan"
uci rename firewall.@zone[1]="wan"
uci rename firewall.@forwarding[0]="lan_wan"
uci del_list firewall.lan.network="${WG_IF}"
uci add_list firewall.lan.network="${WG_IF}"
uci -q delete firewall.wg
uci set firewall.wg="rule"
uci set firewall.wg.name="Allow-WireGuard"
uci set firewall.wg.src="wan"
uci set firewall.wg.dest_port="${WG_PORT}"
uci set firewall.wg.proto="udp"
uci set firewall.wg.target="ACCEPT"
uci commit firewall
/etc/init.d/firewall restart

# Configure network
uci -q delete network.${WG_IF}
uci set network.${WG_IF}="interface"
uci set network.${WG_IF}.proto="wireguard"
uci set network.${WG_IF}.private_key="${WG_KEY}"
uci set network.${WG_IF}.listen_port="${WG_PORT}"
uci add_list network.${WG_IF}.addresses="${WG_ADDR}"
uci add_list network.${WG_IF}.addresses="${WG_ADDR6}"
# Add VPN peers
uci -q delete network.wgclient
uci set network.wgclient="wireguard_${WG_IF}"
uci set network.wgclient.public_key="${WG_PUB}"
uci set network.wgclient.preshared_key="${WG_PSK}"
uci add_list network.wgclient.allowed_ips="${WG_ADDR%.*}.0/${WG_ADDR#*/}"
uci add_list network.wgclient.allowed_ips="${WG_ADDR6%/*}/${WG_ADDR6#*/}"
uci commit network
/etc/init.d/network restart

/etc/config/network currently looks like the following

config interface 'wg0'
    option proto 'wireguard'
    option private_key '<Private_Key>'
    option listen_port '51820'
    list addresses ''

config wireguard_wg0 'wgclient'
    option public_key '<Public_Key>'
    option preshared_key '<Preshared_Key>'
    list allowed_ips ''
    option persistent_keepalive '25'
    option route_allowed_ips '1'

But wg0 setting up fails as followes.

Mon Jan 11 22:50:38 2021 daemon.notice netifd: Interface 'wg0' is now down
Mon Jan 11 22:50:38 2021 daemon.notice netifd: Interface 'wg0' is setting up now
Mon Jan 11 22:50:38 2021 daemon.notice netifd: wg0 (7160): Error: Unknown device type.
Mon Jan 11 22:50:38 2021 daemon.notice netifd: wg0 (7160): Unable to modify interface: Protocol not supported
root@OpenWrt:~# ifconfig wg0
ifconfig: wg0: error fetching interface information: Device not found

In Network->Interfaces of Lucy, it looks like the following

Please help me to set up wg0 interface
Thanks in advance

1 Like

Try reinstalling the packages and reloading the modules, in addition check the output:

ubus call system board
1 Like

Thanks for your reply

I reinstalled the package and reloaded the modules using the script file, but the same failure.
However, when I run the script file, it ends with the following message.

 * Populating IPv6 mangle table
   * Zone 'lan'
   * Zone 'wan'
   * Zone 'vpn'
 * Set tcp_ecn to off
 * Set tcp_syncookies to on
 * Set tcp_window_scaling to on
 * Running script '/etc/firewall.user'

Is configuring network looks ok?

And the following is the output of 'ubus call system board'

root@OpenWrt:/etc/wireguard# ubus call system board
	"kernel": "5.4.86",
	"hostname": "OpenWrt",
	"system": "MediaTek MT7621 ver:1 eco:3",
	"model": "Xiaomi Redmi Router AC2100",
	"board_name": "xiaomi,redmi-router-ac2100",
	"release": {
		"distribution": "OpenWrt",
		"version": "SNAPSHOT",
		"revision": "r15460-211fed5f49",
		"target": "ramips/mt7621",
		"description": "OpenWrt SNAPSHOT r15460-211fed5f49"

Do you have any other suggstion?

1 Like

It looks like a snapshot-specific issue that is typically resolved by performing a clean build.


How should I do perform a clean build?

If you are building the firmware yourself:

Otherwise, just download and re-flash a fresh snapshot build:


As I already installed and configured some other modules, I'm a little reluctant to reflash a fresh snapshot again.

Do you have any other idea?
If not, I'll probably try to reflash.

I just reflashed a fresh snapshot build from the below link for my router, but wg0 can't be setup

root@OpenWrt:~# ifconfig wg0
ifconfig: wg0: error fetching interface information: Device not found

Do you have any idea for this?

You can try to build your own image including the necessary modules:

File a bug if the problem persists:

Thanks for your reply

I flashed clean snapshot and system upgrade to another device of the same kind, then wg0 sets up ok

1 Like

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.