NetShoot Troubleshoot Docker Networking Issues
Docker networking can be complicated to troubleshoot and to know what connectivity issues are seen from the container standpoint. Netshoot is a Docker container that contains various network troubleshooting tools and utilities. It can help you diagnose and solve networking issues within your Docker environment.
Table of contents
What is Netshoot?
Netshoot is a Docker container itself that provides network diagnostic tools. You can use the tools to do things like tcpdump, iproute2, net-tools, traceroute, and others. It is an open source project and is designed to be lightweight and fast to use, being built on Alpine Linux a light distro that is miniaml.
that provides various network diagnostic and troubleshooting tools for your underlying networking infrastructure. It includes command line tool options like tcpdump, iproute2, net-tools, traceroute, etc. Netshoot is an open-source project that is available on GitHub and Docker Hub. So, you have the tools you need to verify, troubleshoot, and validate your network’s stack.
Netshoot can be used to diagnose and troubleshoot various networking issues, such as:
Connectivity issues
DNS resolution issues
Routing issues
Firewall issues
Performance issues
Check out the official Github repo here: nicolaka/netshoot: a Docker + Kubernetes network trouble-shooting swiss-army container (github.com)
Getting Started with Netshoot
To use Netshoot for troubleshooting your Docker network, you need to have Docker installed on your system. If you don’t have Docker installed, you can follow the installation instructions for your operating system.
Once you have Docker installed, you can download Netshoot from Docker Hub using the following command:
docker pull nicolaka/netshoot
This command downloads the latest version of Netshoot from Docker Hub.
Once you have downloaded Netshoot, you can start a new container using the following command:
docker run --rm -it --privileged nicolaka/netshoot
This command starts a new Netshoot container and gives you an interactive shell inside the container. The –rm option tells Docker to remove the container when you exit the shell, and the –privileged option gives the container privileged access to the host system.
Using Netshoot to Troubleshoot Docker Networking Issues
Note the following common network troubleshooting tools you have access to with netshoot.
Ping
Ping sees if hosts are dead or alive from your network connection and if these are reachable for admins to be able to test. For instance, if you want to see if you can ping the Google DNS server:
ping 8.8.8.8
Traceroute
You can identify the path fo the routed packets and if there are any issues along the way with traceroute. If you want to trace the route of packets to Google’s DNS server, you can use the following:
traceroute 8.8.8.8
This command shows the path packets take from your container to the Google DNS server. You see other details like latency, etc.
Tcpdump
Tcpdump captures and analyzes network traffic for admins to look at. You can use tcpdump to diagnose various issues. You can troubleshoot things like connectivity, performance, and security related issues nad other things. To capture all network traffic on the Docker bridge network, you can run the following command:
tcpdump -i docker0
From the Docker bridge network interface (docker0). You can use various options with tcpdump to filter the captured traffic based on things like source or destination IP.
Netstat
Netstat is a tool to see active network connections. For example, to view all active TCP connections on your Docker container with this command:
netstat -ant
IP
The ip command is a powerful tool for managing network interfaces, routing tables, and many other networking core components. You can use the ip command to view and modify network interface configurations for your container. View your IP addresses with the following:
ip address show
This command shows the IP addresses of all network interfaces on your container, along with the interface name and status.
NSLookup
NSLookup is a tool to help with DNS resolution issues. It’s always DNS right? You can use NSLookup to look up DNS records for a domain name and verify if DNS resolution is working correctly. To look up the DNS records for the Google DNS server:
nslookup 8.8.8.8
This command shows the DNS records for the Google DNS server, such as the IP address, hostname, and domain name.
Dig
Dig provides more detailed information about DNS records. You can look up the DNS records for the Google DNS server using Dig, you can run the following command:
dig google.com
This command shows the DNS records for the Google domain, such as the IP address, hostname, and domain name.
Netshoot and Kubernetes network troubleshooting
You can also use Netshoot to troubleshoot networking problems in Kubernetes also and not just Docker containers.
To start a new Netshoot container in the same network namespace as an existing pod that you want to troubleshoot, you can use the kubectl run command with the –rm and –attach options, like this:
kubectl run netshoot --rm -it --image nicolaka/netshoot --overrides='
{
"spec": {
"nodeName": "your-node-name",
"containers": [
{
"name": "netshoot",
"image": "nicolaka/netshoot",
"stdin": true,
"tty": true,
"command": [
"/bin/bash"
],
"securityContext": {
"privileged": true
}
}
],
"hostNetwork": true
}
}
' -- /bin/bash
The –overrides option provides deployment metadata that tells Kubernetes to start the new container in the same network namespace as the existing pod. You can replace your-node-name with the name of the node where the pod is running.
Key Differences Between Netshoot and Other Tools
Netshoot is kind of like a swiss army knife. It has the tool that you need depending on what you are trying to do. You really won’t find a more fully featured tool in a single Docker container than Netshoot. It includes necessary tools and utilities to diagnose things.
It is also very lightweight. It uses very few system resources so when you spin it up, you don’t have to worry about it hogging resources on your Docker container host just to troubleshoot.
Wrapping up
Docker networking can be a bear to troubleshoot if you don’t have something like Netshoot. Sometimes you can only guess what is going on without the tools needed. Netshoot allows you to get inside the container itself and issue networking commands from the container’s perspective so you can see exactly what is going on. Have you used it before?