Quick tip for Windows users who are still trapped with WSL version 1 due to very specific reasons, you can use the same CMD executables straight from your Linux VM, and with an easy enhancement you can create an alias for these and pass parameters just like if you were running them from CMD.
The use-case is: you can’t upgrade your VM to WSL2 and under WSL1 some binaries don’t work since it’s not a full linux Kernel. In my case it was basic troubleshooting tools such as traceroute, which is broken under WSL1.
1 2 3 4 5 6 7 | traceroute tcpip.me traceroute to tcpip.me (159.203.122.127), 30 hops max, 60 byte packets 1 * * * 2 * * * 3 * * * 4 * * * 5 * * * |
So you can either open a new CMD tab and run your tracert from Windows but what if you are working with scripts in your linux VM? Luckily for WSL1 users, the subsystem can browse the Windows filesystem and run the same executables as in your CMD. Write “note” and tab, you will see how it autocompletes to notepad.exe, and if you hit enter it will open your beloved Windows notepad app. Same goes for command line executables such as tracert, for which we can use “tracert.exe”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | tracert.exe tcpip.me Tracing route to tcpip.me [159.203.122.127] over a maximum of 30 hops: 1 31 ms 4 ms 3 ms 192.168.1.1 2 21 ms 23 ms 19 ms * 3 19 ms 19 ms 19 ms 10.50.3.9 4 21 ms 19 ms 19 ms 10.50.3.10 5 * * * Request timed out. 6 * 135 ms * 94.142.97.65 7 167 ms 172 ms 172 ms 94.142.119.188 8 152 ms 168 ms 171 ms ae-12.r04.miamfl02.us.bb.gin.ntt.net [129.250.9.85] 9 159 ms 149 ms 149 ms ae-3.r23.miamfl02.us.bb.gin.ntt.net [129.250.3.141] 10 172 ms 152 ms 148 ms ae-4.r24.asbnva02.us.bb.gin.ntt.net [129.250.2.86] 11 * * 173 ms ae-0.r25.asbnva02.us.bb.gin.ntt.net [129.250.2.36] 12 180 ms 142 ms 140 ms ae-4.r21.nwrknj03.us.bb.gin.ntt.net [129.250.6.117] 13 154 ms 148 ms 151 ms ae-2.r00.nycmny17.us.bb.gin.ntt.net [129.250.3.51] 14 141 ms 142 ms 143 ms ce-0-12-0-2.r00.nycmny17.us.ce.gin.ntt.net [157.238.179.70] 15 143 ms 161 ms 165 ms * 16 * * * Request timed out. 17 * * * Request timed out. 18 146 ms 145 ms 145 ms 159.203.122.127 Trace complete. |
Now, at times it may be tricky to find your Windows executables because some Linux binaries have similar names and hitting tab may take several attempts, so let’s create an alias. Go to your Linux home directory and assuming you are using bash, modify your .bashrc file to add a new alias for the executable you want to leverage from Windows, i’ll name mine the same, just “tracert”.
1 2 3 4 5 6 | cd ~ ll | grep bashrc #just making sure my .bashrc is here, odd habits. -rw-r--r-- 1 user1 user1 3819 Jan 15 23:22 .bashrc echo -e '#My custom aliases\nalias tracert="tracert.exe"' >> .bashrc |
Now let’s make sure the alias was added correctly to your .bashrc file with “tail”.
1 2 3 4 5 6 7 8 9 10 | tail .bashrc . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi #My custom aliases alias tracert="tracert.exe" |
Looking good, so now let’s give it a try, this time let’s use parameters as well (i love -d in tracert).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | tracert -d tcpip.me Tracing route to tcpip.me [159.203.122.127] over a maximum of 30 hops: 1 3 ms 2 ms 4 ms 192.168.1.1 2 31 ms 26 ms 19 ms * 3 20 ms 19 ms 19 ms 10.50.3.9 4 20 ms 19 ms 30 ms 10.50.3.10 5 * 21 ms * 213.140.39.160 6 114 ms * * 94.142.97.65 7 152 ms 151 ms 151 ms 94.142.119.188 8 169 ms 151 ms 152 ms 129.250.9.85 9 149 ms 148 ms 149 ms 129.250.3.141 10 147 ms 148 ms * 129.250.2.86 11 * * * Request timed out. 12 143 ms 141 ms 141 ms 129.250.6.117 13 167 ms 142 ms 146 ms 129.250.3.51 14 142 ms 142 ms 158 ms 157.238.179.70 15 142 ms 141 ms 142 ms * 16 * * * Request timed out. 17 * * * Request timed out. 18 166 ms 164 ms 165 ms 159.203.122.127 Trace complete. |
There you go, you can do this basically for any Windows executable when using WSL1. Remember this is just a workaround when not having a WSL2 VM. If you do, you get a full linux Kernel and binaries such as traceroute and tracepath should work normally.