############### UNIX Management ############### :Author: Dimitry Dukhovny .. contents:: .. .. note:: .. To help support this site and learn more, check out .. `Command Line Kung Fu: Bash Scripting Tricks, Linux Shell Programming Tips, and Bash One-liners `_. .. note:: To donate to the maintenance of these pages, do send BTC to bc1qkw0pp78kv67zrgp8xds7qrqen7mhlz0rs5p8p5 .. .. image:: images/qrcode-gnomon-static.png Networking ========== Get IP address -------------- .. code-block:: bash :linenos: ifconfig -a For a particular interface, such as **eth0**, use .. code-block:: bash :linenos: ifconfig eth0 Alternately... .. code-block:: bash :linenos: ip a Set the new IP address ---------------------- For these examples, we will assign **192.168.100.100** in our **/24** to the interface **eth0** with a default gateway of **192.168.100.254**. Set the IP directly from the commandline ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: bash :linenos: ifconfig eth0 192.168.100.100 netmask 255.255.255.0 route add default gw 192.168.100.254 Set the IP in configuration files on a Redhat-like systems ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: bash :linenos: :caption: /etc/network/interfaces/ifcfg-eth0 TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no IPV6_FAILURE_FATAL=no NAME=eth0 DEVICE=eth0 ONBOOT=yes IPADDR=192.168.100.100 NETMASK=255.255.255.0 # for Centos6 PREFIX=24 # for Centos7 GATEWAY=192.168.100.254 DNS1=192.168.100.1 DNS2=192.168.100.2 DOMAIN=mydomain.gov Set the IP in configuration files on a Debian-like systems ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: bash :linenos: :caption: /etc/network/interfaces source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback address 127.0.0.1 # The primary network interface iface eth0 inet static address 192.168.100.100 netmask 255.255.255.0 gateway 192.168.100.254 dns-nameservers 192.168.100.1 Patches and Updates =================== Update package list in Redhat-like systems ------------------------------------------ .. code-block:: dosbatch :linenos: yum check-update yum update Update package list in Debian-like systems ------------------------------------------ .. code-block:: bash :linenos: apt-get update apt-get upgrade Trouble: Stale process or process with runaway threads ======================================================= Use this to kill processes of a certain name owned by a certain user that is older than a certain time. In this example, we want to kill every **httpd** process owned by **apache** that is older than **five hours**. .. code-block:: bash :linenos: /usr/bin/find /proc -maxdepth 1 -user apache \ -type d -mmin +300 -exec basename {} \; | \ xargs ps | grep httpd | awk '{print $1}' | \ xargs -i kill -HUP {} Trouble: My process claims a file is not found =============================================== * `strace` your way through the stack to see where it looks for files * Assuming a program called `black_box` in the current directory... .. code-block:: bash :linenos: strace -f -s 255 -o /tmp/black_box.out ./black_box .. Trouble: My process claims it is missing a library =================================================== * List the expected libraries and install any missing ones. * `error while loading shared libraries` * `cannot open shared object file` * Assuming a program called `black_box` in the current directory... .. code-block:: bash :linenos: ldd ./black_box 2>&1 | grep "not found" ..