S
S
symnoob2019-08-17 12:08:50
Docker
symnoob, 2019-08-17 12:08:50

WSL2 - how to bind a permanent IP address?

Hello everyone,
how to bind a permanent IP address to WSL2?
thanks in advance

Answer the question

In order to leave comments, you need to log in

5 answer(s)
W
WolfWalker, 2019-08-21
@WolfWalker

Get wsl ip:

#!/bin/bash

rawIp=$(ip addr | grep eth0)
rawIp=$(echo $rawIp | egrep -o '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}\/')

echo ${rawIp::-1}

Resolve dns in windows:
#!/bin/bash

hosts=/c/Windows/System32/drivers/etc/hosts
newHosts=/tmp/hosts

cp $hosts $newHosts

originIp=$(cat $newHosts | grep wsl)
newIp="$(getWslIp) wsl"

sed -i "s/$originIp/$newIp/" $newHosts

cp $newHosts $hosts

D
Dimonchik, 2019-08-17
@dimonchik2013

https://github.com/MicrosoftDocs/WSL/issues/418

O
Ostyuchenko, 2020-06-01
@Ostyuchenko

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0

D
dayman092, 2020-12-22
@dayman092

there are already several answers about static ip address.
How now to add it to the firewall exceptions in the antivirus?

E
evilmolen, 2021-06-15
@evilmolen

Old question, but relevant as always
There is a handy Go tool - https://github.com/shayne/go-wsl2-host

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question