Latest version
Dismiss Be notified of new releases. Create your free GitHub account today to subscribe to this repository for new releases and build software alongside 50 million developers.
Tcpreplay is a suite of free Open Source utilities for editing and replaying previously captured network traffic. Originally designed to replay malicious traffic patterns to Intrusion Detection/Prevention Systems, it has seen many evolutions including capabilities to replay to web servers. There's PReplay for Windows, tcpreplay and capedit for Linux/UNIX, and then a bunch of specialized tools for replaying specific types of traffic, usually related to. ZeroLogon can be used to exploit a serious vulnerability in Windows Domain Controllers. I was recently asked if you could detect a ZeroLogon attempt using a SensorFleet-based Sensor. It is easy because we have plug & play support for Emerging Threats intrusion detection ruleset and ZeroLogon was added to the ruleset on September 14th 2020. This release contains bug fixes only: Increase cache buffers size to accomodate VLAN edits Correct L2 header length to correct IP header offset Fix warnings from gcc version 10 Heap Buffer Overflow in randomizeiparp Use after free in getipv6next Heap Buffer Overflow in gitipv6next Call pcapfreecode on pcapcompile.
Released:
tool to replay and work with pcap and smcap (smithproxy capture) files
Project description
Support
For comments, feedback or new feature discussion feel free to drop a message to pplay-users@googlegroups.com mailing list.If you can make use of .deb package, visit download section of this site.
History
recently I’ve been in the need of reproducing some issue with DLP, while I was provided with pcap when DLP was not involved in the traffic flow and everything was working.Originally I was trying to utilize netcat, however I’ve always ended up with some (my) mistake, or simply I just sent CR when it should have been CRLF… Reproduction was frankly tedious task.
Then I gave up on manual work, and tried tcpreplay. This is really fantastic tool in case you want to replay exactly what you have in pcap. However I quickly realized that DLP is changing sequential numbers of inspected TCP traffic, so it couldn’t have been used it too!! Looking around the net, I decided to write something myself which will help me now and next time it can help others too.
Quick start
PPlay is tool to replay/resend application data, it doesn’t care of transport layer parameters (which we want, reasons described above). It will grab only the payload from connection you explicitly specify and will make new connection and plays the content in the right order. Of course, you will need to run pplay on server and on client too, with the same pcap file parameter and also with other quite important arguments.
All data about to be sent will be printed out to be confirmed by you. When receiving data, it will tell you if they differ from what we expect and how much; there are 3 levels, OK, modified, different. If they differ significantly (marked as different), they will not be considered as the part of the expected data, so in most cases the logic of packet ordering will stay stable.
Output is colored; RED means anything related to received stuff, GREEN everything to data to be sent, or YELLOW for command line and other data eligible to be sent in the future but not now. WHITE is usually program notifications. At the first sight pplay’s output might look bit a messy, but colors really help.
Replaying PCAP
Run server side pplay instance
Replaying SMCAP (smithproxy captures)
Run client pplay instance
Replaying PPlayScript
pplay also knows how to export data to a “script”. This is extremely convenient to do if you are repeating the same test again and again, needing to change parts of the payload dynamically. Output script is in fact a python class, containing also all necessary data, no –pcap or –smcap arguments are needed anymore.
You can produce script with –export <scriptname> (filename will be scriptname.py). You can then use it by –script scriptname (instead of –pcap or –smcap arguments).For example:
You can use “script” as the sniff file (NOTE: missing .py in –script argument)
Main purpose of it is the need of dynamic modification of the payload, or other “smart” stuff, that cannot be predicted and programmed for you in pplay directly.
Simplistic script example:
As you might see this gives to your hands power to export existing payload with –export and modify it on the fly as you want. You can make a string templates from it and just paste values as desired, or you can write even quite complex code around!
Creating and using self-contained package
This feature is extremely useful for automation. You can use SMCAP, PCAP or pplayscript, embed it into pplay itself,and use this self-contained pplay version by executing it over the SSH (or the other way, SSH is just the most obvious).
The rest is just the same normal pplay. Please note that pplay over ssh needs a bit different approach, so we execute it with:
Launch embedded server
Pack smcap file into pplay, resulting file in /tmp/smbla.py – smbla.py will contain pplay and also data from provided smcap file and launch server (on r32 host, options suitable for automation), using packed pplay:
Launch embbedded client
Please note that you need to have installed python-scapy on both remote servers. Of course, SSH needs to be reachable (i.e. you need to create firewall pin-holes for it).Also for (and only for) the automation you might want to create ssh key without the passphrase.
More details
PPlay forgets everything about original IP addresses. It’s because you will be testing it in your lab testbed. Only thing it will remember is the the destination port, for server side pplay it’s important, meaning the port where it should listen for incoming connections. But that’s really it.
Client-side pplay will connect to the server-side. Once connected, you will see on one side green hex data and on the other yellow hex data. For HTTP, the client-side would be typically green, since HTTP comes with the request first. On the line above green hex data you will also see e.g. “[1/2] (in sync) offer to send –>”. In sync is important here. Those data should be sent now according to pcap.If you see yellow data, that side is not on it’s turn, and you will not see also “(in sync)” above them.
Yellow or green, pplay will act on behalf of you by default in 5 seconds => green data will be sent.Hint: you can set –noauto, or –auto <big_seconds> program argument to change autosend feature. This feature could be also toggled on/off during the operation with “i” command shortcut.
Launch on remote SSH server
new in version 1.7.0You have learned so far how to “pack” data inside pplay. It’s pretty useful, but you need to always –pack, create a file, send it to the other side, and execute there.Even though in previous examples we mentioned how to send packed over ssh stdin, you still need linux command-line ssh.Since version 1.7.0 you can actually utilize –remote-ssh parameter, and pplay will send over ssh itself!
Nice on this is you don’t need anything on remote servers, just pure python. Nothing else is needed.
Limitation: since python on remote server receives pplay from stdin which must be closed to actually launch it, commands from standard input are not supported and –nostdin is automatically added to remote command line. Recommended running with --exitoneot and --auto.
Connect client using SOCKS
Another useful feature might be to use proxy for client outgoing connection (perhaps you are testing such a proxy, like I am).To do so, use –socks parameter, taking IP address optionally suffixed with a port, ie. 10.0.0.1:1080
Commands
Below hex data (green or yellow), there is some contextual help for you: pplay is waiting for your override action to it’s default – autosend. At the time being, you can enter:
Data sources
PPlay also supports smithproxy output, just use –smcap instead of –pcap argument option.You can wrap the traffic into SSL, just use –ssl option. With smithproxy together, pplay is quite powerful pair of tools: you can easily replay “decrypted” smcap file from smithproxy and wrap it again into SSL to further test.
Hint: Smithproxy it’s SSL mitm proxy written by me in C/C++, faking certificate subject. It utilizes iptables TPROXY target. SSL traffic is signed by local CA and plaintext is logged into files.
Requirements
Tool doesn’t have too requirements. You have to have installed scapy and colorama python packages.
Scapy is used to parse pcaps and to have scapy available for future features - runs on Linux, Mac and Windows (see instructions how to install scapy on windows here). It’s known to not work in Cygwin.
Note: I am deciding to drop scapy in the future.Colorama is responsible for multiplatform coloring. On windows, unpack zip-file, run cmd and run python setup.py install. That should make it.
I would recommend to run pplay in linux, I haven’t tested it on Windows yet.
SMCAP2PCAP tool
This tool is a bit hack. Basically it replays smcap file, while using tcpdump to sniff the traffic. There are dozens of reasons why you would like to convert smcap file to pcap. This is the tool for that purpose.
Also, this tools is very basic. There is only argument it takes: smcap file. Name and location of the converted pcap will be printed out.
Release historyRelease notifications | RSS feed
2.0.5.post3
2.0.5.post2
2.0.5.post1
2.0.5
2.0.4
2.0.2
2.0.1
2.0.0.post6
2.0.0.post5
2.0.0.post1
1.7.4.post1
1.7.3.post5
1.7.3.post4
1.7.3.post3
1.7.3.post2
1.7.3.post1
1.7.3
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size pplay-2.0.5.post3-py3-none-any.whl (34.7 kB) | File type Wheel | Python version py3 | Upload date | Hashes |
Filename, size pplay-2.0.5.post3.tar.gz (36.3 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for pplay-2.0.5.post3-py3-none-any.whl
Algorithm | Hash digest |
---|---|
SHA256 | 96b5186d555ab10711dce65b33150bcbfca0cf131a48bcf02a19f58e925e62f9 |
MD5 | 6f9fbdc7220fc1da4391347156226cb5 |
BLAKE2-256 | a471a8af768ba41a7eb65df4f1f423ad747ca10efac482df5b278bb8895f7399 |
Hashes for pplay-2.0.5.post3.tar.gz
Algorithm | Hash digest |
---|---|
SHA256 | afdf511e1ba80114bbbdb67f674b738f8d6d298f9234b6b49aa3bba2a21ce7b0 |
MD5 | 42b72bd80c64a3ddb4df12367500baf4 |
BLAKE2-256 | e0a9fd7bfd9fcee757f8336576f809f0bf4e9d823d9284dbc3f731aab6a1d533 |
The Windows Subsystem for Linux (WSL) is a great solution for developers to natively work within Linux right on their Windows 10 version desktop. Let’s go deep in this ultimate guide on how to get started with WSL on Windows 10 in this Ultimate Guide!
If you’ve spent way too much time partitioning hard drives to have several Linux distros installed with Windows, you’re in luck with this article. The fairy code-mother at Microsoft has decided to give you another option: The Windows Subsystem for Linux (WSL). WSL makes running a Linux distribution alongside Windows so much easier, and more flexible.
In this tutorial, you’ll learn how to get started with WSL. You’ll learn how to get started to learning how to use some nifty tools making WSL even more versatile than using bash or PowerShell on their own.
WSL: Linux as a Windows App
WSL or C:WindowsSystem32wsl.exe is a Windows tool that allows you to install a Linux distribution as an app from the Windows store.
Since WSL is a simple Windows executable, you can call it from a cmd command prompt or PowerShell terminal. We’ll go deeper into that topic later. For now, it’s important to understand a little more about what WSL is doing under the hood.
WSL vs WSL2
There are two different versions of Windows Subsystem for Linux, WSL and WSL2. If you have the Windows 10 build 18917 or higher, you should run WSL2. Even if you don’t, everything else in this post will work for either version.
The main difference between them comes down to system call (syscall); a programmatic way an operating system calls a service.
Syscall can get complicated quickly. I won’t go into syscall here, but if you’d like to read more about it check out MSDN article here.
At a high level, when you run a command through WSL, syscall uses a driver to interpret that on the Windows kernel. WSL2 then uses a virtualized Linux kernel that’s running in the background and gets updated through Windows update.
WSL2 works a lot more like a traditional virtual machine (VM) where Windows would be the host and the WSL distro is the VM guest.
Here is a high-level summary of how these changes affect calling resources in WSL:
At the time of this writing, WSL2 is still not generally available. To replicate everything in this post, you’ll need a Windows Insiders preview build and to dig through Microsoft’s Github issues list to get WSL2 to work. Depending on your urgency, you may be better off waiting until WSL2 goes GA. You’ve been warned!
Installing WSL
Setting up Windows Subsystem for Linux involves installing a Linux distribution alongside Windows 10. But in a way that allows the two different operating systems to interact with each other.
To install Windows Subsystem for Linux on Windows, the only requirement is that you have a 64-bit Windows 10 device. Different versions of WSL require different builds of Windows, but they can run alongside each other. WSL and WSL2 can be used interchangeably in this post.
If you’re going to follow along be sure you have:
- Windows 10 build 16215 or later (WSL1)
- Windows build 18917 or later (WSL2)
Note: As WSL is still in active development at the time of writing, some of these features may require builds higher than 16215. As you’re following along, pay attention to which build you need for which feature. You may have to check the versions yourself to figure out what if any Windows updates are necessary.
Setting up WSL via Training Video
If you’re more of a visual learner, feel free to watch this TechSnips video on how to get WSL up and running.
If you don’t prefer the learn via video on how to set up WSL, read on.
Checking your Windows 10 Build
As mentioned earlier, certain builds of Windows 10 are required for using WSL. To make sure you can use any given version of WSL, first check which build of Windows you are running. There are a few different ways to do this, but the easiest two are from cmd or PowerShell.
Finding Window 10 Build with Cmd
In a command prompt, run systeminfo
. Here you will see your Windows 10 operating system version near the top of the results as shown below.
Finding Windows 10 Build with PowerShell
In PowerShell, you can check the Windows registry to find your Windows 10 build. Below is a code snippet you can use for this purpose.
Once you’ve confirmed that you are running a compatible Windows 10 build, you can now download a WSL Linux distro from the Microsoft store. You can install as many distributions of Linux as your device will support and use them with your Windows installation.
Enable the Windows Subsystem for Linux Windows Feature
In an administrative PowerShell console session, run Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
and reboot. This will install the Microsoft Windows Subsystem for Linux Windows feature.
Download the Linux Distro of Choice
Once Windows 10 comes back up, go to the Microsoft store and download a distro of Linux by searching for ‘WSL’. Windows Subsystem for Linux does not install distributions by itself, it only allows you to install them after it’s been set up.
The rest of the article will reference a Ubuntu 18.04 distribution But, at the time of this writing, there are other available as well such as:
- Ubuntu 16.04 LTS
- Ubuntu 18.04 LTS
- OpenSUSE Leap 15
- OpenSUSE Leap 42
- SUSE Linux Enterprise Server 12
- SUSE Linux Enterprise Server 15
- Kali Linux
- Debian GNU/Linux
- Fedora Remix for WSL
- Pengwin
- Alpine WSL
Updating to Windows Subsystem for Linux 2
At the 2019 MS Build conference, Microsoft announced a new version of WSL (WSL2). To the end user, WSL2 was mostly the same as WSL1 with one big difference: WSL2 runs a full Linux kernel instead of emulating system calls to one.
WSL2 is also faster and more compatible with Linux-native applications (or applications that were designed to run only on Linux).
If you are running Windows build 18917 or later and you have WSL already installed, you can update to WSL2 by running Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
with Administrator privileges, then reboot.
Configuring Linux Distros to Work with WSL2
Once your device starts back up, you can start using WSL2 on your existing installed distros. Below you’ll see a few steps to run through to configuring your existing Linux distros for WSL2. Open a PowerShell console and:
- List which versions of Linux you have installed by running
wsl -l
orwsl --list
. - Once you have the list, copy the name of the distro you want to run with WSL2 and run
wsl --set-version <Distro> 2
, replacing <Distro> with the name you copied earlier. - Confirm the command was successful by running
wsl -l -v
orwsl --list --verbose
. This command will return a full list of WSL distros and the version each distro is using.
Note that you can also set your default WSL version for any distros you install in the future to WSL2 by running wsl --set-default-version 2
Reverting Linux Distros from WSL2 to WSL1
If you want to revert a distro from WSL2 back to WSL1, run wsl --set-version <Distro> 1
, replacing <Distro> with that distro’s name.
Starting up WSL
To start using WSL, open up a PowerShell terminal and type wsl
. If you’ve set up WSL correctly, you’ll enter a bash terminal running on the WSL distro of choice. From here, you can run any Linux commands you wish.
Below you will find a reference to all of the options the wsl.exe provides when starting up.
Arguments for running Linux binaries
Once you get comfortable using these switches, you’ll find that running and managing applications through WSL is much easier than managing Linux virtual machines on your own.
Quick tip: Discover all flags and arguments for to WSL by running wsl --help
.
When you’re finished, type exit
to go back back to the PowerShell terminal.
Sharing Windows/Linux Resources via WSL
One of the best parts of WSL is that it allows you to seamlessly share Windows and Linux resources with each other. At this time, you can share file systems, environment variables, network resources and command line interpreters like cmd and PowerShell.
All examples you will see in this section are via the WSL Ubuntu Linux distro. Your mileage may vary if you’ve chosen to download a different distro.
Sharing File Systems
The file system is one of the most useful things to share with WSL. WSL allows you to work with both file systems as if they were one.
The Windows 10 file system is mounted as a directory in Linux while your Linux file system will be mounted as a folder in Windows.
Finding the Linux File System from Windows with Environment Variables
When you install a Linux distro with WSL, it will sometimes add a Windows environment variable. In the case of the WSL Ubuntu Linux distro, it will create an environment variable called UBUNTU_HOME. This environment variable points to the Linux /home/ubuntu directory from both Windows and WSL Ubuntu.
The path defined in UBUNTU_HOME can be used to run scripts that use resources across them, or set a default location for the Windows terminal (covered later).
Other distros may define a similar environment variable. Inspect the Windows environment variables with the PowerShell command Get-ChildItem -Path $Env:
after installing a new Linux distro to see if any may have been added.
This environment variable shortcut is handy if you want to put everything in the /home/ubuntu directory. But let’s dig a little deeper into how it got there and how else you can reach it.
Finding the Linux File System from Windows via the Microsoft Store Packages Folder
Not every WSL distro is guaranteed to come with an easy way to reference it. It’s important that you learn how to find the Linux file system an alternative way.
Since most WSL Linux distributions will be installed from the Microsoft store, you can look for the Linux file system in the same place as other Windows store apps. Navigate to %USERPROFILE%AppDataLocalPackages to find the directory where your Windows store apps go. Then assume control of the folder as this is usually protected by default.
You will see many subfolders in the packages folder where your Linux distrubution file system may be presented. The WSL Ubuntu distro, for example, was under the CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc folder for me.
If you navigate into the package folder, you will find the Linux file system. For WSL Ubuntu, it’s located in the LocalStaterootfs folder. This is the root directory of your Linux distro.
Finding the Windows File System from Linux
To find the Windows 10 file system from Linux, open up WSL in Windows. WSL will then bring up a bash terminal. This bash terminal will start in your UBUNTU_HOME directory by default.
You can also find the root of your Windows storage volumes as well. Each of your Windows letter drives (C, D, E, etc) is treated as a mounted drive from the WSL Linux file system. You’ll find each volume mounted as /mnt/c, /mnt/d, etc as long as you have root privileges.
The WSL2 Filesystem
Navigating the WSL filesystem is fairly straightforward. Anyone not familiar with a Linux file system structure will appreciate being able to navigate it with the Windows Explorer. Bu if you want to switch to WSL2, it’s going to be a little more complicated.
WSL2 changes how everything works under the hood for sharing file systems. For starters, the filesystem is now a virtual hard disk in vhdx format instead of a directory.
You can find the vhdx file under %USERPROFILE%AppDataLocalPackagesCanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgscLocalState for an WSL Ubuntu distro. Unfortunately though, the rootfs folder is gone unlike WSL1.
Windows Explorer File Navigating not Possible (For Now)
At the time of writing, there is no way to navigate the Windows file system via WSL Linux file system outside of the cp
or Copy-Item
commands from the terminal.
How To Install Tcpreplay On Windows 7
You’ll find that VHDX files can be mounted in Windows with the Disk Manager tool. But, the virtual disks cannot be mounted while the WSL distro is registered.
Sharing Environment Variables
Environment variables are a crucial part of any operating system, making it easy to reference binaries and executables anywhere in your applications.
Before Windows 10 build 17063, the only environment variable shared between Windows 10 and WSL Linux was the PATH variable. Since then it is possible to share environment variables by using WSLENV the environment variable.
Using the WSLENV environment variable to share other environment variables can feel a little meta. To share environment variables across platforms, you actually have to set environment variables inside of another environment variable.
Overview
Sharing environment variables is a three-step process below. The only major difference when sharing across Windows/Linux is the switch argument used (full reference below).
- Define environment variable in Windows or Linux.
- Set the WSLENV environment variable equal to the previously defined environment variable followed by a switch argument (for path translation).
- Read the environment variable in Windows or Linux.
Sharing Options
You can make variables available four different ways depending on which platform you’d like the environment variable to show up on using switches (table shown below).
- Windows filesystem to only be available from itself
- WSL filesystem to only be available from WSL
- WSL filesystem to be available on both WSL Linux and Windows
- Windows filesystem to be be available on both WSL Linux and Windows
What Is Tcpreplay
Path Translation
The main reason to share environment variables is for path translation. As you may already know, Windows has user profile folders as Linux has user profile directories, for example. Each user has a predetermined “home folder” like C:Users<username> on Windows and /home/<username> on Linux.
Using the /p
and /l
switches, the WSL will translate these folder paths between platforms.
Sharing and Translating Windows Paths with Linux
You can share a single path or multiple paths at once using the /p
and /l
switches.
At a Windows command prompt and with a Windows environment variable defined called DESKTOP, assign a value of DESKTOP/p
to the WSLENV variable. This allows you to access it from WSL Linux. You can see an example below.
The exact same procedure can be performed for multiple paths at once using the /l
switch.
Sharing and Translating Linux Paths with Windows
To share and translate Linux path with Windows is the same procedure as it Windows although using Linux-specific commands to set environment variables.
How Tcpreplay Work
For a deeper look at sharing environment variables, check out, this Microsoft article.
Sharing Network Resources: WSL Differences Explained
The networking component is another handy resource to share between Windows and WSL Linux. Networking is where WSL gets a little difficult. There are a couple pieces of information you should know about though depending on the version of WSL you are using.
WSL vs WSL2 Networking
You’ll find that depending on the version of WSL you’re using, networking is going to be completely different. It’s important to understand these differences because they can have a major impact on how you develop applications in WSL.
Physical vs. Virtualized Network Interfaces
The most prominent difference is how WSL exposes Windows network interfaces. In WSL1, WSL uses the same physical network interfaces as Windows 10 uses. Using the same network interfaces means that WSL network interfaces will share the same IP addresses as Windows 10 does.
WSL1 networking is fine if you can use the same IP network across both Windows and WSL but if you need them to differ, you’ll have to use WSL2.
In WSL2, the network interfaces are virtualized. Virtualized network interfaces mean that WSL2 network instances can hold different IP configurations than their Windows 10 counterparts.
At the time of this writing, IP addresses for WSL2 Linux use Network Address Translation (NAT) to access network resources on Windows, though Microsoft has mentioned removing NAT is high on their backlog of issues to fix.
Client DNS Resolution
WSL and WSL2 will still both generate /etc/resolv.conf and /etc/hosts files to allow for DNS resolution. As long as you don’t explicitly override that behavior in /etc/wsl.conf, client DNS resolution will continue to work as expected.
You’ll learn more about the wsl.conf file later in the post.
Using PowerShell and Bash Together
One of the coolest features of WSL is the ability to seamlessly pass information to and from PowerShell and Bash on WSL.
PowerShell –> Bash
Since the WSL executable accepts input from the pipeline, you can call the wsl.exe command inside of PowerShell and accept stdin. This allows you to use WSL to pass entire objects from PowerShell into the WSL which then get processed with the bash terminal. You can see an example below.
Bash –> PowerShell/Cmd
You can also pass information from bash in the WSL to PowerShell and cmd just as easily. Below you can see an example of executing the Linux ls command and passing the output to the PowerShell Select-Object
cmdlet via the pipeline.
You can also call some Windows cmd utilities from the WSL and pass the output back to Linux as long as both commands are in the system path.
Remember that the WSL knows what the system path is on both sides because it has access to the Windows PATH variable by default
Below you can see that you can run ipconfig, which is a Windows command, from within the WSL and pass that output to the Linux grep command. You can also see the opposite of calling the Linux command which and passing output to the Windows ipconfig command.
Translation Issues
There are some caveats to passing command output back and forth between bash and PowerShell.
One big problem is how PowerShell and bash return information. PowerShell is an object-oriented programming language while bash is a string manipulation tool. Any PowerShell objects piped to bash will flattened as a string. Conversely, any bash output piped to PowerShell will be converted to a string object.
You can get around the behavior somewhat by converting or explicitly casting object types in PowerShell like in the example below. But if you are expecting to pass objects between PowerShell and WSL without any extra work, you’re going to be disappointed.
By casting the bash date as the [datetime]
class in PowerShell, now we have a valid PowerShell object that we can use in our script. If you are writing scripts that need to go from Windows to WSL and back again, it’s possible to do with a little massaging to the code.
Install a Windows Subsystem for Linux GUI with Xfce4
When a command line isn’t enough, it’s time to break out the GUIs. If you need to run a graphical utility on WSL, explore a custom distro, or you’re not familiar with bash yet, you can install a Linux GUI.
Xfce
Tcpreplay Edit
Linux has many available desktop environments. One of the most common ones to set up for WSL is called Xfce. At the time of this writing, Xfce is at version 4. Other desktop environments are available but in this article, you’ll learn how to get Xfce4 set up.
xRDP
When you have a Linux desktop environment set up, you’ll need a service that understands the RDP protocol. In this article, we’ll focus on the xRDP server. xRDP is an open source RDP server for Linux that allows you to use RDP clients to connect to Linux just as if you can Windows hosts.
Setting Up
To access a Linux GUI from Windows with Xfce4 and xRDP, follow the instructions below. In a WSL terminal:
- Download and install Xfce4 – Download and install Xfce4 using the command
sudo apt-get -y install xfce4 && sudo apt-get -y install xubuntu-desktop
. This will take a while. Stand by. - Install the xRDP server – Download and install xRDP by running
sudo apt-get -y install xrdp
. - Configure xRDP for xfce4 –
echo xfce4-session > ~/.xsession
- Restart xRDP –
sudo service xrdp restart
- Find the WSL distro IP address –
ifconfig | grep inet
At this point, you should be able to open an RDP session from Windows 10. Open up remote desktop connection window using mstsc
and provide the Linux IP address found in step #5.
If all goes well, you can open an RDP connection to the Linux distro that’s running on your Windows operating system as shown below.
Tips and Tricks
Now that you know the basics of WSL and how to use it, what’s next? Fortunately there are a lot of tools that are either built for or work well with WSL.
Setting WSL Configuration Items at Bootup with wsl.conf
A configuration file exists in the WSL at /etc/wsl.conf. This file contains configuration settings that run every time the WSL distro is started. When the wsl.conf file exists, WSL will ingest any setting in this file every time the Linux distro is started.
There are a few different sections inside of the wsl.conf file you can configure.
- Automount – Mounting drives from Windows at start
- Network – Generate resolv.conf or the hosts file
- Interop – Enabling or disabling interop with Windows
For more details on the wsl.conf file, check out the Microsoft Set WSL Launch Settings page.
Developing on WSL with Visual Studio Code (VS Code)
VS Code seemingly integrates with everything and WSL is no exception. From within VS Code, you can set up a workspace on your WSL Distro but manipulate it completely with VS Code on Windows. You don’t even need to have a terminal running!
To set up VS Code on Windows to work with WSL, you’ll first obviously need VS Code for Windows installed. Also be sure you have the Remote – WSL VS Code extension installed.
Once you’ve got the extension installed, you can now connect to it by opening a WSL terminal and running code <workspace>
. <Workspace>
is the directory where you’d like to run VS Code from. VS Code will then detect that you are in a WSL distro, open a window, and establish a connection to to the workspace.
Confirm it worked by noticing the WSL connection icon in the lower left corner of VS Code. You should see that it has the name of your WSL distro.
You can even use the built-in terminal to interact directly with the WSL workspace. There’s no need to run a separate window for git bash commands.
Adding Windows Subsystem for Linux to the Windows Terminal
Another useful use-case of WSL is to add the WSL console it to the Windows Terminal.
From within Windows Terminal, you add each WSL distro in it’s own tab. You can also customize the look of each tab so you don’t get lost.
If you’re using a WSL distro that sets an environment variable for the user directory like UBUNTU_HOME, you can also set that as the starting directory for your terminal.
If you’d like a complete video walkthrough on setting up WSL to work with the Windows Terminal, check out the TechSnips how-to video below.
Closing Thoughts
Microsoft released the WSL to allow Linux developers the ability to develop on Windows. So far, the WSL has been a step in the right direction.
It appears that the WSL is going to be a crucial component of Microsoft’s new open-source friendly strategy. If Microsoft is going to take on Apple to be the devices that developers write their code on, it’s going to be an uphill battle. But WSL is a strong card to play.
WSL brings about many many welcome benefits to developers like:
- Significantly lighter weight than running local Linux VMs
- Removing the overhead of installing and managing a hypervisor
- No more requirement for multi-partitioned hard drives
- No more complicated grub bootloaders
WSL just turns on and runs so we can all code happily ever after.
Comments are closed.