UNIX Management

Author:

Dimitry Dukhovny

Note

To donate to the maintenance of these pages, do send BTC to bc1qkw0pp78kv67zrgp8xds7qrqen7mhlz0rs5p8p5

_images/qrcode-gnomon-static.png

Networking

Get IP address

1ifconfig -a

For a particular interface, such as eth0, use

1ifconfig eth0

Alternately…

1ip 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

1ifconfig eth0 192.168.100.100 netmask 255.255.255.0
2route add default gw 192.168.100.254

Set the IP in configuration files on a Redhat-like systems

/etc/network/interfaces/ifcfg-eth0
 1TYPE=Ethernet
 2BOOTPROTO=none
 3DEFROUTE=yes
 4IPV4_FAILURE_FATAL=no
 5IPV6INIT=no
 6IPV6_FAILURE_FATAL=no
 7NAME=eth0
 8DEVICE=eth0
 9ONBOOT=yes
10IPADDR=192.168.100.100
11NETMASK=255.255.255.0 # for Centos6
12PREFIX=24 # for Centos7
13GATEWAY=192.168.100.254
14DNS1=192.168.100.1
15DNS2=192.168.100.2
16DOMAIN=mydomain.gov

Set the IP in configuration files on a Debian-like systems

/etc/network/interfaces
 1source /etc/network/interfaces.d/*
 2
 3# The loopback network interface
 4auto lo
 5iface lo inet loopback
 6        address 127.0.0.1
 7
 8# The primary network interface
 9iface eth0 inet static
10        address 192.168.100.100
11        netmask 255.255.255.0
12        gateway 192.168.100.254
13        dns-nameservers 192.168.100.1

Patches and Updates

Update package list in Redhat-like systems

1yum check-update
2yum update

Update package list in Debian-like systems

1apt-get update
2apt-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.

1/usr/bin/find /proc -maxdepth 1 -user apache \
2 -type d -mmin +300 -exec basename {} \; | \
3 xargs ps | grep httpd | awk '{print $1}' | \
4 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…

1strace -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…

1ldd ./black_box 2>&1 | grep "not found"