Ongoing Linux Cheatsheet

Reference For Me, Reference For You?

I often find myself using certain commands on semi-regular basis. Not regular enough to remember but enough to know what I am looking for. This is my list of snippets that others might find useful. I will do my best to update this from time to time.

On a side note, I primarily use Ubuntu 18.04 (20.04 upgrade will likely happen when it comes out). I occasionally use distros other than Ubuntu but they are typically Debian based.

Variables that you want to alter will be denoted as $VAR_NAME.


Photo by Kevin Horvat on Unsplash

Connecting To Wifi Using CLI

- This uses the command line version of NetworkManager (nmcli)
- Obviously you need to know your network name and password
- Determine your network interface with 'nmcli device status'. Four columns will be displayed. Find wifi in the Type column and then the associated Device name is the interface name.

Commands: 

nmcli d wifi connect $NAME password $PASSWORD iface $INTERFACE

Create Network Name Space And Move Device Into It

- Move a device into a network interface and get an IP lease.
- Network namespaces can be used to group or sandbox network devices. Docker containers use network namespaces for isolation.
- Once devices are in network namespaces you can access them using
ip netns exec $NET_NS $COMMAND

Commands:

# create network namespace
sudo ip netns add $NET_NS

# move move network interface into created ns
sudo ip link set dev $INTERFACE

# bring interface up
sudo ip netns exec $NET_NS ip link set dev $INTERFACE up

# get IP lease
sudo ip netns exec $NET_NS dhclient $INTERFACE


Get Docker Container ID and PID

- For some networking black magic there is a need to know container information. I normally use this in a script so I will be storing the results as bash variables.
- container_name is the plain, user assigned name of the container, maybe db_server or python_box, etc

Commands:

container_id=$(docker ps -aqf "name=container_name")
container_pid = $(docker inspect --format '{{ .State.Pid }}' "container_name")


Install Build Dependencies for a Package

Sometimes chasing down all the packages and the correct versions of said packages is REALLY TEDIOUS.

Commands:

sudo apt-get build-dep $PACKAGE_NAME


Comments

Popular posts from this blog

Hindsight 20/20: University Productivity Tips and Tricks

Linux and SSH for Noobs