I followed this answer and added in the interfaces file these lines:
auto wlx...
iface wlx... inet static
address 192.168.2.150
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid <my_router>
wpa-psk <my_wpa_key>
dns-nameservers 8.8.8.8 192.168.1.1
ifconfig outputs my Wifi dongle as wlx.. instead of wlan0 (that's why I changed it).
When doing sudo ifup wlx... I get:
wpa_supplicant: /sbin/wpa_supplicant daemon failed to start
run-parts: /etc/network/if-pre-up.d/wpasupplicant exited with return code 1
Failed to bring wlx...
Why does this appear?
The bigger context is described here: Make Ubuntu Server to connect automatically to WiFi, but it was closed as duplicate.