Friday, 15 May 2015

Using Screen


If you've been frustrated with managing multiple network device GUI terminals (i.e. Lots of PuTTY sessions) or just prefer to use the keyboard for most of the work, you may be interested in a utility called 'screen'.

Screen provides the ability to run multiple virtual terminals inside of a single terminal and manage these virtual terminals purely through the keyboard. Terminals can be configured to dump a running history, copy and paste and can be detached to resume the virtual terminal session again later.

You can either install screen in a Linux host through the native package manager or on Windows through Cygwin. I'm using screen in a mintty terminal on Windows.

Start by creating the .screenrc file in your home directory. This file contains the user specific configuration for screen. You can use 'vi' to do this. My configuration contains the following:

startup_message off
shell -/bin/bash
hardstatus alwayslastline
hardstatus string "%w"



The first line removes the startup/welcome message. The shell command specifies the shell to use for new virtual terminals. The hardstatus command refers to a status line that takes up the last row of text on the screen. alwayslastline ensures that it always stays and the "%w" signifies that the number and name of all the terminals should be displayed in the hard status line.

Once you start screen with this configuration, you should see something like the following.



There is a single terminal (0), entitled 'bash', that you can use as a normal terminal or try some of the commands below.


Ctrl-A Ctrl-A
Switch to the previous window
Ctrl-A d
Detach from screen (terminals are left running and can be reattached to later)
Ctrl-A c
Create a new terminal
Ctrl-A #
Change to terminal number signified by '#'
Ctrl-A H
Start logging terminal output to screenlog.# ('#' indicates terminal number)
Ctrl-A A
Change the window title
Ctrl-A S
Split the window in to multiple terminals. Each is visible at the same time.
Ctrl-A tab
Switch between split windows
Ctrl-A k
Kill the current window
Ctrl-A X
Remove the current split window


Here is an example of a split screen instance. An SSH session is being run in the top section and a VI session for a file is being run in the bottom section.



If you detach a screen instance using "Ctrl-A d", you can reattach using "screen -r" or get a listing of the screen instances to reattach to using "screen -ls"

$ screen -ls
There are screens on:
        1744.pty0.scyth (Attached)
        5008.pty4.scyth (Detached)
2 Sockets in /tmp/uscreens/S-jreichman.



Links
http://en.wikipedia.org/wiki/GNU_Screen
http://www.gnu.org/software/screen/manual/screen.html

Thursday, 7 May 2015

Debian simple network configuration


I recently deployed a Debian 8.0 box and found that the location for the networking configuration was a little different than the CentOS and RHEL systems I have been used to. After some poking around, I found that the network configuration is stored in /etc/network/interfaces and include files in the /etc/network/interfaces.d directory.

root@debian:/etc/network# ls -l /etc/network
total 24
drwxr-xr-x 2 root root 4096 May  3 23:28 if-down.d
drwxr-xr-x 2 root root 4096 May  3 23:28 if-post-down.d
drwxr-xr-x 2 root root 4096 May  3 23:28 if-pre-up.d
drwxr-xr-x 2 root root 4096 May  4 00:37 if-up.d
-rw-r--r-- 1 root root  240 May  4 20:26 interfaces
drwxr-xr-x 2 root root 4096 May  4 22:43 interfaces.d
lrwxrwxrwx 1 root root   12 May  3 20:24 run -> /run/network


Configuration for an interface can be placed in the interfaces file or by adding a new file under interfaces.d. Files in the interfaces.d directory are sourced by the interfaces file.

root@debian:/etc/network# cat interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback


To do a basic network configuration for eth0, put the following in /etc/network/interfaces.d/eth0 (substituting correct network addressing.)

##
# eth0 configuration

auto eth0
iface eth0 inet static
        address 192.168.1.10
        netmask 255.255.255.0
        gateway 192.168.1.254
dns-nameservers 192.168.1.254


The auto keyword defines that this interface should be brought up automatically and the iface keyword begins the configuration for the interface, which in this case is static.


More information: https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_basic_syntax_of_etc_network_interfaces