linux · Server · tips and tricks

Ubuntu Server: Tips and Tricks

Ubuntu Server

Ubuntu 16.04: Solving new nomenclature names for interfaces (or not)

Ubuntu 16.04 (Xenial Xerus) replaces the now familiar network interface names (e.g. eth0) with slightly less familiar Predictable Nework Interfaces Names (e.g. enp0s3 – introduced since Ubuntu 15.10). It means your network interfaces in ifconfig output will no longer follow the ethX pattern.

To fallback to the older nomenclature append the following kernel parameter (within quotes like the other options) to the line starting with GRUB_CMDLINE_LINUX_DEFAULT or GRUB_CMDLINE_LINUX in /etc/default/grub:

net.ifnames=0

Or simply use sed command to add this parameter:

$ sudo sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="net.ifnames=0"/g' /etc/default/grub

Update the grub to make effect:

$ sudo update-grub

Reboot your system:

$ sudo reboot

Rename the interface

First get your devices MAC Address by:

$ ip link

The output show by like:

3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
link/ether 20:68:9d:xx:xx:xx brd ff:ff:ff:ff:ff:ff

Your devices MAC address is 20:68:9d:xx:xx:xx

Just create the file /etc/udev/rules.d/10-network.rules

$ sudo nano /etc/udev/rules.d/10-network.rules

Add following line:

SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="mynet"

Replace name with your wanted name mynet and aa:bb:cc:dd:ee:ff with your devices MAC address.

Now just reboot your computer and the device name should have changed.

References:

Network configuration – ArchWiki: Change device name
http://askubuntu.com/a/690603/139248

Swap file setting

Check for swap space

$ sudo swapon -s

Create Swap file

Allocate the space you want to use for your swap file using the fallocate utility. For example, if we need a 1 Gigabyte file, we can create a swap file located at /swap by typing:

$ sudo fallocate -l 1G /swap
$ sudo mkswap /swap
$ sudo swapon /swap

Keep the swap file permanently:

$ sudo nano /etc/fstab

Add line to fstab file:

/swap none swap sw 0 0

Setting Swappiness

Below line is not needed, optional, will set the swappiness. The default value is 60. It will changed to 10 automatically after adding vm.swappiness value and rebooting. Permanent changes are made in /etc/sysctl.conf via the following configuration line (inserted, if not present):

$ echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

Note: This value (10) is sometimes recommended to improve performance when sufficient memory exists in a system.

To prevent the file from being world-readable, you should set up the correct permissions on the swap file:

$ sudo chown root:root /swap
$ sudo chmod 0600 /swap

Apply all above changes

$ sudo reboot

To see the memory used and check if the swap is active:

$ free -m

Forced to run fsck on every startup

That way if the machine crashes for some reason, it will always do a fsck on boot-up and be up all the time.

Automatically repair filesystems with inconsistencies on every startup:

$ sudo nano /etc/default/rcS

Change:
#FSCKFIX=no

To:
FSCKFIX=yes

Turn Off IPv6

If you’re not using a IPv6 protocol, then you should disable it because most of the applications or policies not required IPv6 protocol and currently it doesn’t required on the server. Go to network configuration file and add followings lines to disable it.

To disable ipv6, you have to open /etc/sysctl.conf:

$ sudo nano /etc/sysctl.conf

Add these lines to the bottom of sysctl.conf:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

Then run sudo sysctl -p or reboot

Command Line Quick Tips & Tricks

  1. Find out whether a package is installed or not:
    $ dpkg -s [package-name]
    $ dpkg -s apache2-mpm-worker
    $ dpkg -l apache*
  2. List files in a package which has been installed:
    $ dpkg -L [package-name]
    $ dpkg -L python-openssl
  3. Update package list, then preform all upgrades:
    $ sudo apt-get update
    $ sudo apt-get upgrade
  4. Create new user and grant root privileges:
    $ sudo adduser newuser
    $ sudo usermod -a -G sudo newuser # add to sudo group
  5. Delete a user:
    $ sudo userdel newuser
    $ sudo rm -rf /home/newuser # delete the files of this user
  6. List all users:
    $ cat /etc/passwd

    Or:

    $ lastlog
  7. View current user uid and groups:
    $ id
  8. Add user to a group, eg: dialout group:
    $ sudo usermod -a -G dialout
  9. Change time zone:
    $ sudo dpkg-reconfigure tzdata
    $ less /etc/timezone # verify timezone has changed
    $ sudo service cron restart # restart cron so it pick up the timezone change
  10. Manual time synchronization:
    $ sudo ntpdate -u ntp.ubuntu.com
  11. List mounted partitions:
    $ df -h
  12. View size of a particular file or folder:
    $ du -h myfile
    $ du -sh myfolder
  13. Find the full path of a command:
    $ which [command]
    $ which python
  14. View appended data as a file grows (good to view logs files):
    $ tail -f filename
  15. Change server hostname:
    $ sudo sh -c "echo new-host-name > /etc/hostname"
    $ sudo service hostname restart
  16. View information of the linux distribution:
    $ lsb_release -a
  17. Check the OS installation date:
    $ ls -ld /var/log/installer
  18. Find a computer name in a LAN from the IP address:
    $ nslookup IP-NUMBER

    Or:

    $ nmap -sP IP-NUMBER
Anúncios

Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s