13 February 2012

64. Two network cards on the same network, splitting traffic

Some thoughts on using two LAN network cards: While it sounds instinctively neat, the main issue here is to decide how it should actually work i.e. where is what traffic going.

One idea is send traffic to one subset (e.g. 192.168.1.1-100) of IP addresses via one card, and another subset (e.g. 192.168.1.101-255) to another.

This isn't a job for a firewall (other than to restrict/allow traffic) but a situation where you use routing.

Some background
To see your routing table, run
sudo route 
(or sudo route -n if you want to resolve names)

Here's the routing table of the gateway in this post where eth0 is connected to the Outside World, and eth1 is connected (and acting as the gateway of) a subnet of 192.168.0.-255:

Kernel IP routing table
Destination     Gateway            Genmask   Flags Metric Ref    Use Iface
default             xxx.xxx.xx7.254    0.0.0.0           UG     0        0        0    eth0
xxx.xxx.xx0.0     *                      255.255.248.0   U     0         0        0    eth0
link-local            *                      255.255.0.0       U     1000   0        0    eth1
192.168.1.0       *                      255.255.255.0   U     0         0        0    eth1

It says:
Route everything by default to the gw at xxx.xxx.xx7.254,
unless the target is in network xxx.xxx.xx0.0-255 or
unless the target is in 169.254.0.0 - 169.254.255.255 (link-local is 169.254.0.0) or
unless the target is in 192.168.1.0-255

Here's the routing table of a box with a single card attached to the LAN:

Kernel IP routing table
Destination     Gateway              Genmask   lags Metric Ref    Use Iface
default          192.168.1.1             0.0.0.0          UG    0      0        0 eth0
192.168.1.0     *                    255.255.255.0      U     0      0       0 eth0

Finally, here's the routing table of a box with two cards connected to different LANs:

Kernel IP routing table
Destination     Gateway             Genmask         Flags Metric Ref    Use Iface
default         192.168.2.1            0.0.0.0         UG     0      0        0 eth3
default         192.168.1.1            0.0.0.0         UG     0      0        0 eth2
192.168.1.0     *                     255.255.255.0   U     0      0        0 eth2
192.168.2.0     *                     255.255.255.0   U     0      0        0 eth3
Default and * both equal 0.0.0.0 using sudo route -n.


SOLUTIONS
1. Two cards on the same network using /etc/network/interfaces -- very simple:
Yup, I talked about route before, but this is a less granular method using /etc/network/interfaces:

auto eth2
iface eth2 inet static
address 192.168.1.105
netmask 255.255.255.0
gateway 192.168.1.1
auto eth3
iface eth3 inet static
address 192.168.1.130
netmask 255.255.255.128
gateway 192.168.1.1


This configuration gives the following sudo route -n:

Kernel IP routing table
Destination         Gateway         Genmask      Flags Metric    Ref    Use   Iface
0.0.0.0                192.168.1.1           0.0.0.0           UG       0         0        0      eth2
192.168.1.0           0.0.0.0        255.255.255.0     U        0         0        0      eth2
192.168.1.128        0.0.0.0       255.255.255.128     U        0         0        0      eth3

Which is exactly what we wanted.


Solution 1.b using network-manager
In gnome 3/gnome-shell, go to system settings/network/select your interface (e.g. eth1), click on Configure (bottom right corner), and select the IP v4 tab and change the address and netmask as shown in solution 2. Or hit 'Routes...' in the lower left corner and do your configuration there...




Solution 2. Two cards on the same network and another card connected to 'internet'

eth0 is connected to the outside world, eth1 acts as the gateway for 192.168.1.0-127, and eth2 acts as the gateway for 192.168.1.128-255

I configured this in network-manager by setting:
eth0 to dhcp
eth1 to 192.168.1.1, mask 255.255.255.0, gw 192.168.1.1
eth2 to 192.168.1.129, mask 255.255.255.128, gw 192.168.1.129
I didn't edit route settings.

The corresponding /etc/network/interfaces settings would probably be:
auto eth0
iface eth0 inet dhcp
auto eth1
iface eth1 inet static
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.1
auto eth2
iface eth2 inet static
address 192.168.1.129
netmask 255.255.255.128
gateway 192.168.1.129



Anyway, here's the sudo route -n:
Kernel IP routing table
Destination        Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0            130.194.167.254 0.0.0.0          UG    0         0        0 eth0
130.194.160.0   0.0.0.0         255.255.248.0     U     0         0        0 eth0
169.254.0.0       0.0.0.0         255.255.0.0         U     1000   0        0 eth1
192.168.1.0       0.0.0.0         255.255.255.0     U     0         0        0 eth1
192.168.1.128   0.0.0.0         255.255.255.128 U     0         0        0 eth2


Using this configuration you should probably set the gateway for eth3 in solution 1 to 192.168.1.128 -- that way you split all the traffic and in effect create two subnets (so technically, the 'same LAN' isn't really true)

Don't forget to open up your firewall to allow broadcasting from both 192.168.1.127 and 192.168.1.255

09 February 2012

63. Iptables for LAN with one internet connected gateway; sharing internet connection using iptables

Here I show how to share an internet connection with clients on a LAN. It's based in part on the iptables which firestarter generates when setting up connection sharing -- I think one could probably get away with dropping the INBOUND/OUTBOUND sections for the gateway server.

You will probably find that you need to open more ports, depending on your network services. Hopefully it's obvious from the instructions below how to do that. As always, use what you find below as a starting point and expand and correct it as you fool around with it.

While it's easier to use a gui like gufw or firestarter (see previous post), it's easier to get an absolute overview of your firewall configuration if you define each rule using iptables. It's also not that difficult and with a bit of trial and error you can work it out.

The usual caveats apply -- a good 2/3 of my posts are written as I'm teaching myself, while the remainder describe easy, useful, but not always obvious, things and programmes which makes life easier. This lands in the former category.

--- START HERE ---

My network:
One computer has two cards. eth0 is connected to the outside world, eth1 is connected to a switch making up a LAN. Each client is connected to the switch and has static IP (set in /etc/network/interfaces)

The clients are the easiest, so we'll start with them

Client:
create /etc/firewall-rules.sh (e.g. sudo vim /etc/firewall-rules.sh) and put the following in it:

sudo iptables -F #FLUSH

#INPUT
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT #network access
sudo iptables -A INPUT -i lo -j ACCEPT                        #127.0.0.1
sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT -s 192.168.1.0/24 #ssh
sudo iptables -A INPUT -p tcp --dport www -j ACCEPT -s 192.168.1.0/24 #web server
sudo iptables -A INPUT -p tcp --dport nfs -j ACCEPT -s 192.168.1.0/24 #needed for nfs
sudo iptables -A INPUT -p udp --dport nfs -j ACCEPT -s 192.168.1.0/24 #needed for nfs
sudo iptables -A INPUT -p tcp --dport sunrpc -j ACCEPT -s 192.168.1.0/24 #needed for nfs 
sudo iptables -A INPUT -p udp --dport sunrpc -j ACCEPT -s 192.168.1.0/24 #needed for nfs 
sudo iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT -s 192.168.1.0/24 #ping
sudo iptables -A INPUT -p udp --dport 60003 -j ACCEPT -s 192.168.1.0/24 #sinfo/d
sudo iptables -A INPUT -m limit --limit 15/minute -j LOG --log-level 7 --log-prefix " Dropped by firewall "
sudo iptables -A INPUT -j DROP                          #drop all else

#OUTPUT
sudo iptables -A OUTPUT -o lo -j ACCEPT #127.0.0.1
sudo iptables -A OUTPUT -j ACCEPT          #all outgoing ok

#FORWARD
sudo iptables -A FORWARD -p icmp --icmp-type 8 -j ACCEPT

#Default behaviour
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT DROP 
sudo iptables -P FORWARD DROP
Next, change ownership and permission

sudo chown root firewall-rules.sh
sudo chmod 700 firewall-rules.sh

Finally, edit /etc/network/interfaces and put
post-up sh /etc/firewall-rules.sh
as the last line. If you use post-up routing rules as well you can put those before or after.

Done!


The Gateway:
We need to allow the local network access to the services of the gateway, such as apt-cache. We also need to pass through traffic to the outside world.

Here's the gateway's /etc/firewall-rules.sh:

sudo iptables -F #FLUSH
# T1 -> eth0 --> inet, eth1 --> LAN (192.168.0/24)

#table nat
sudo iptables -t nat -P PREROUTING ACCEPT
sudo iptables -t nat -P INPUT ACCEPT
sudo iptables -t nat -P OUTPUT ACCEPT
sudo iptables -t nat -P POSTROUTING ACCEPT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

#table mangle
sudo iptables -t mangle -P PREROUTING ACCEPT
sudo iptables -t mangle -P INPUT ACCEPT
sudo iptables -t mangle -P FORWARD ACCEPT
sudo iptables -t mangle -P OUTPUT ACCEPT
sudo iptables -t mangle -P POSTROUTING ACCEPT 

#main table
sudo iptables -N OUTBOUND
sudo iptables -N INBOUND

#INPUT
sudo iptables -A INPUT -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT #allows network access
sudo iptables -A INPUT -i lo -j ACCEPT                                                #127.0.0.1
sudo iptables -A INPUT -i eth1 -p tcp --dport ssh -j ACCEPT -s 192.168.1.0/24 #ssh
sudo iptables -A INPUT -i eth1 -p tcp --dport www -j ACCEPT -s 192.168.1.0/24 #web server
sudo iptables -A INPUT -i eth1 -p tcp --dport nfs -j ACCEPT -s 192.168.1.0/24 #needed for nfs
sudo iptables -A INPUT -i eth1 -p udp --dport nfs -j ACCEPT -s 192.168.1.0/24 #needed for nfs
sudo iptables -A INPUT -i eth1 -p tcp --dport sunrpc -j ACCEPT -s 192.168.1.0/24  #needed for nfs 
sudo iptables -A INPUT -i eth1 -p udp --dport sunrpc -j ACCEPT -s 192.168.1.0/24 #needed for nfs 
sudo iptables -A INPUT -i eth1 -p icmp --icmp-type 8 -j ACCEPT -s 192.168.1.0/24  #ping
sudo iptables -A INPUT -i eth1 -p udp --dport 60003 -j ACCEPT -s 192.168.1.0/24 #sinfo/d
sudo iptables -A INPUT -i eth1 -p tcp --dport 3142 -j ACCEPT -s 192.168.1.0/24             #apt-cache
sudo iptables -A INPUT -i eth1 -d 192.168.1.1 -j INBOUND                                                   #needed for gw -> clients
sudo iptables -A INPUT -i eth0 -s 192.168.1.0/24 -j REJECT 
sudo iptables -A INPUT -m limit --limit 15/minute -j LOG --log-level 7 --log-prefix " Dropped by firewall "
sudo iptables -A INPUT -j DROP                                                       #drop all else


#OUTPUT
sudo iptables -A OUTPUT -o lo -j ACCEPT #localhost 127.0.0.1
sudo iptables -A OUTPUT -o eth0 -j ACCEPT #eth0: all outgoing ok
sudo iptables -A OUTPUT -o eth1 -j ACCEPT                               #eth1: all outgoing ok

#FORWARD
sudo iptables -A FORWARD -p icmp -j ACCEPT 
sudo iptables -A FORWARD -p tcp -s 192.168.1.0/24 -j ACCEPT     #forward everything from local LAN
sudo iptables -A FORWARD -p udp -s 192.168.1.0/24 -j ACCEPT    #forward everything from local LAN
sudo iptables -A FORWARD -i eth0 -j OUTBOUND                           #need both for pass-through
sudo iptables -A FORWARD -i eth1 -j OUTBOUND                           #need both for pass-through


#INBOUND
sudo iptables -A INBOUND -j ACCEPT -m state --state RELATED,ESTABLISHED                              
sudo iptables -A INBOUND -s beryllium -j ACCEPT
sudo iptables -A INBOUND -j ACCEPT -s 192.168.1.0/24

#OUTBOUND
sudo iptables -A OUTBOUND -j ACCEPT

#Default behaviour
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT DROP 
sudo iptables -P FORWARD DROP

And that's about it.

To check that it loaded do

sudo iptables -L -n -v

The -n is because of this.

Keep on checking what goes into /var/log/firewall.log to see whether you should open more ports or use a more generous (or strict) firewall policy.



Edit: the following was the old way of doing it. The downside is that
1. it gets loaded very late in the boot sequence
2. it doesn't reload on sudo service networking restart

I've migrated away from network-manager, but it might require the method below. Use if the first method doesn't load the firewall rules.

edit /etc/rc.local and put 
sh /etc/firewall-rules.sh
as the second-to-last line to make the rules be added on each boot.

Remember the sudo iptables -m limit --limit 15/minute -j LOG --log-level 7 --log-prefix " Dropped by firewall " line? It doesn't actually do anything yet.

Edit /etc/rsyslog.conf and put
kern.=debug /var/log/firewall.log
anywhere. Restart the service:

sudo service rsyslog restart

There's now a firewall.log in your  /var/log dir.



There is one caveat:

IMPORTANT: for some reason receiving large files via sftp in filezilla FROM a client to the gateway gives

Error: Incorrect MAC received on packet
Error: File transfer failed after transferring 32,768 bytes in 1 second
or
Error: Server sent disconnect message
Error: type 2 (protocol error):
Error: "Packet corrupt"
Error: File transfer failed

Transferring large files TO a client works fine from the gateway and is blazingly fast. Transferring files between clients also works fast and securely.

i.e. on a client I can easily receive files from the gateway. On the gateway I can easily put a file on a client. The opposite directions don't work, whether I do it on the client or on the gateway. It seems like there should be an obvious iptables fix. My network cards are rtl-8169 gigabit pci cards and/or intel e1000 pro

NFS works fine for filetransfer (see this post) but I'm working on figuring out the incorrect MAC problem.

I've already tried with
sudo iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

Also, even a firewall consisting of nothing but (apart from flush):

sudo iptables -P INPUT ACCEPTsudo iptables -P OUTPUT ACCEPTsudo iptables -P FORWARD ACCEPT

doesn't solve it

Links to this post:
http://www.debian-srbija.iz.rs/p/kako-da.html

62. Sharing a folder between computers using nfs on Debian

A year ago I posted about getting nfs set up for a local network as part of a longer post -- here it is reposted, with minimal changes to make up for the substitution of portmap for rpcbind in debian. Hopefully it'll be clearer. Also, nfs is such a universally useful thing that it should be promoted among a wider audience.

I followed this post to get up and running (scroll down) with nfs. Here's my take on it:

UPDATE: with the first comment below in mind, I changed this post a little bit. The folder /shared on the master node is shared with the client, which mounts it under /home/me/shared, instead of sharing the folder /home/me/shared on the host and mounting it as /home/me/shared on the client. I basically want to drive home the message that you're mounting an NFS share in the same way as any other disk resource -- you can mount it in whatever location you want, regardless of where the folder is found on the host.

Server
On the master node (here: 192.168.1.1 - beryllium) which hosts the shared folder on its harddrive:
sudo apt-get install nfs-kernel-server nfs-common rpcbind

Let's share /shared

Create it
sudo mkdir /shared

Set permissions for 'all' to be read, write and execute
sudo chmod a+wrx /shared

Edit /etc/exports by adding a line to the end of the file
/shared *(rw,sync)



[Note that this (the *) is inherently insecure. You should restrict access to the NFS mounts via your firewall (e.g. using iptables with -A INPUT -s 192.168.1.0/24 -p udp -m udp --dport 2049 -j ACCEPT;  -A INPUT -s 192.168.1.0/24 -p udp -m udp --dport 111 -j ACCEPT for a local subnet 192.168.1.1-255).  You can also use 
/shared 192.168.1.0/24(rw,sync)

to restrict it similarly directly via /etc/exports. There are more things that can be done, see e.g. here and here. If you are running a cluster with a separate subnet, this is not a great worry. If you are in a situation where security is important, consider using sshfs instead.]

Make stuff happen:
sudo /etc/init.d/nfs-kernel-server restart
sudo exportfs -a

Client
On each client node:
sudo apt-get install rpcbind nfs-common
mkdir ~/shared

Add the following line to the end of /etc/fstab
beryllium:/shared /home/me/shared nfs   rw   0   0

You can mount in a different location if needed -- server:serverfolder localfolder nfs rw 0 0

To get it up and running immediately instead of waiting for reboot:
sudo mount ~/shared


That's it!

Links to this page:
http://forums.debian.net/viewtopic.php?f=5&t=84889

08 February 2012

61. Keeping time with ntp on debian



Set-up
NTP is used to accurately sync the clock on your computer and keep it current.

Install ntp if you haven't already
sudo apt-get install ntp ntpdate
the configuration file is in /etc/ntp.conf

You can have a look through the ntp.conf file and change the server lines to something closer to home if necessary -- you can find server pools for different regions here: http://www.pool.ntp.org/en/

If your clock is off by too much, syncing won't work, so you might want to do this to sync up the first time:

sudo service ntp stop
sudo ntpdate -u 0.pool.ntp.org

 8 Feb 16:28:42 ntpdate[10484]: step time server 121.0.0.41 offset -648.353916 sec

compare the output of date with e.g http://worldtimeserver.com



Now, start the ntp server again:

sudo service ntp start


Running your own local ntp server for your LAN

The NTP daemon will (presumably) run happily in the background and gradually adjust the time if it's off.
For a sub-LAN  you may want to sync e.g. the gateway to the ntp pool, then sync all the local computers to the gateway in order to cut down on traffic, like so.

Here's my version of that link:
server:
Here's /etc/ntp.conf on my server, which is seen as 192.168.1.1 by the local subnet (connected to inet on eth0 and subnet on eth1) . The last two lines were important to get it to work.

driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
server 0.oceania.pool.ntp.org
server 1.oceania.pool.ntp.org
server 2.oceania.pool.ntp.org
server 3.oceania.pool.ntp.org
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1
restrict ::1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
broadcast 192.168.1.255
server 127.127.1.0
fudge 127.127.1.0 stratum 10

sudo service ntp restart
and you're good to go

client:
/etc/ntp.conf
driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
server 192.168.1.1
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1
restrict ::1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
disable auth
broadcastclient
sudo service ntp restart

Checking if the client is connecting to the server.
me@kookaburra:~$ sudo service ntp stop
Stopping NTP server: ntpd.
me@kookaburra:~$ sudo ntpdate 192.168.1.1
 8 Feb 17:22:35 ntpdate[12846]: adjust time server 192.168.1.1 offset -0.008602 sec
me@kookaburra:~$ sudo service ntp start
Starting NTP server: ntpd.
me@kookaburra:~$ sudo ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 beryllium       LOCAL(0)        11 u    2   64    1    0.189   -7.332   0.000

(beryllium is the name of my 192.168.1.1 server.)

60. i18n_translation and no Package:Header error on Debian Testing 32 bit

I'm doing this via an apt-cache server (i.e. the 192.168.1.1 rather than ftp.au.debian.org) -- but the problem is unrelated to the apt-cache server.

Symptom:

Get:1 http://192.168.1.1 testing InRelease [179 kB]
Ign http://192.168.1.1 testing/contrib TranslationIndex
Get:2 http://192.168.1.1 testing/main TranslationIndex [2,154 B]
Ign http://192.168.1.1 testing/non-free TranslationIndex
Get:3 http://192.168.1.1 testing/main i386 Packages [7,146 kB]
Get:4 http://192.168.1.1 testing/contrib i386 Packages [48.9 kB]
Get:5 http://192.168.1.1 testing/non-free i386 Packages [87.5 kB]
Ign http://192.168.1.1 testing/contrib Translation-en_AU
Get:6 http://192.168.1.1 testing/contrib Translation-en [34.8 kB]
Get:7 http://192.168.1.1 testing/main Translation-en [3,722 kB]
Ign http://192.168.1.1 testing/non-free Translation-en_AU                                
Get:8 http://192.168.1.1 testing/non-free Translation-en [62.5 kB]
Fetched 11.3 MB in 2s (4,348 kB/s)                                                          
W: Failed to fetch copy:/var/lib/apt/lists/partial/192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_main_i18n_Translation-en  Encountered a section with no Package: header

E: Some index files failed to download. They have been ignored, or old ones used instead.

Reason:
ftp://ftp.au.debian.org/debian/dists/wheezy/main/i18n/
All the files in that directory are compressed (bz2) -- you need to enable apt-get to decompress .bz2 files.

Solution:
Install bzip2

sudo apt-get install bzip2

at this point gives

Reading package lists... Error!
E: Encountered a section with no Package: header
E: Problem with MergeList /var/lib/apt/lists/192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_contrib_i18n_Translation-en
E: The package lists or status file could not be parsed or opened.

So remove the offending files (2 lines):
sudo rm  /var/lib/apt/lists/192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_contrib_i18n_Translation-en
sudo rm /var/lib/apt/lists/192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_non-free_i18n_Translation-en

Now you can 

sudo apt-get install bzip2

followed by

sudo apt-get update
Hit http://192.168.1.1 testing InRelease
Get:1 http://192.168.1.1 testing/main i386 Packages/DiffIndex [2,038 B]
Get:2 http://192.168.1.1 testing/contrib i386 Packages/DiffIndex [2,023 B]
Get:3 http://192.168.1.1 testing/non-free i386 Packages/DiffIndex [2,023 B]
Ign http://192.168.1.1 testing/contrib TranslationIndex
Hit http://192.168.1.1 testing/main TranslationIndex
Ign http://192.168.1.1 testing/non-free TranslationIndex
Get:4 http://192.168.1.1 testing/contrib Translation-en [34.8 kB]
Get:5 http://192.168.1.1 testing/main Translation-en [3,722 kB]
Get:6 http://192.168.1.1 testing/non-free Translation-en [62.5 kB]
Ign http://192.168.1.1 testing/contrib Translation-en_AU        
Ign http://192.168.1.1 testing/non-free Translation-en_AU
Fetched 103 kB in 4s (25.3 kB/s)
Reading package lists... Done

Done indeed!

07 February 2012

59. Some problems with a headless box with four ethernet cards

I'll put this here more as general information rather than a solution to anything.

The situation:
I got my hands on a tiny WAN server with four ethernet cards (Intel Pro 100). Two of the ports light up when attaching CAT5 cables (eth3 and eth4), two of them remain dead (eth0 and eth1).

I thought I was clever:

/etc/network/interfaces

auto eth0
iface eth0 inet static
address 192.168.1.103
netmask 255.255.255.0
gateway 192.168.1.1
auto eth1
iface eth1 inet static
address 192.168.1.104
netmask 255.255.255.0
gateway 192.168.1.1
auto eth2
iface eth2 inet static
address 192.168.1.105
netmask 255.255.255.0
gateway 192.168.1.1
auto eth3
iface eth3 inet static
address 192.168.1.106
netmask 255.255.255.0
gateway 192.168.1.1

/etc/hosts
127.0.0.1 localhost
192.168.1.103 garfish
192.168.1.104 salmon
192.168.1.105 wallaby
192.168.1.106 kookaburra
192.168.1.1 beryllium
192.168.1.101 boron
192.168.1.102 tantalum
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Well, here's what happened:
I installed Debian Stable on the HDD using virtualbox -- it's a tried an tested method by which instead of creating a virtual HD you attach an external HD via USB and pass it through to a new virtualbox instance which only has a CD or DVD image of a Debian installation medium mounted. I might explain this in more detail in a separate post.

Anyway, installation was fine. I installed the basic tools, ssh-server, file-server etc., but no desktop environment.

I knew that I had to manually set the IP address since the server would be attached to a switch, not a router, so I attached the HDD as an external USB HDD to a tower with a display attached to it, hit F9 during boot to boot from the external harddrive, and things looked ok. Well, the network card hadn't been brought up  -- I guess this is normally done by network-manager even if you don't configure your /etc/network/interfaces

sudo ifconfig eth0 192.168.1.103 netmask 255.255.255.0 up

was enough to get me connected, after which I edited the /etc/apt/sources.list, upgraded to testing, and installed a few network tools and a collecting of non-free drivers for good luck.

I edited the /etc/hosts and /etc/network/interfaces as shown above

What I saw (using tshark -i eth1 on another box on the same local network):
23.630357 192.168.1.103 -> 130.194.1.99 DNS 69 Standard query AAAA
garfish
 23.631220 130.194.1.99 -> 192.168.1.103 DNS 144 Standard query
response, No such name

Anyway, odd, but let's leave it at that.

I put the HDD in the server, then tried to log in via ssh. Nothing. And no response to pinging. Can't reach the apache server running.

Hmm...pulled out the hdd put a crontab script to run once every minute which would run lspci, ip addr and ping back to one of my boxes. Put the hdd back in, started and listened with tshark. Well, the server was pinging away, but I couldn't ping back, nor ssh in, nor connect to port 80.

Looking at the ip addr output:
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.103/24 brd 192.168.1.255 scope global eth0
3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/etherxx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.104/24 brd 192.168.1.255 scope global eth1
4: eth2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.105/24 brd 192.168.1.255 scope global eth2
5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.106/24 brd 192.168.1.255 scope global eth3
    inet6 fe80::20e:b6ff:fe2a:a830/64 scope link
       valid_lft forever preferred_lft forever

Not too shabby looking - eth0 and eth1 are down, but at least the server isn't turning green and projectile vomiting.

But /var/mail/me:
Date: Mon, 06 Feb 2012 17:28:04 +1100
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
>From 192.168.1.103 icmp_seq=1 Destination Host Unreachable
Odd, since I could SEE the pings using wireshark/tshark - but from 192.168.1.106.

Anyway, to make a very long story short -- the solution was to remove eth0 and eth1 from /etc/network/interfaces -- they are dead, and initialising them were causing odd behaviour.


There isn't much of a moral to this story, and the usefulness to other people is perhaps limited, but just in case you do recognise the situation, try limiting yourself to good ethernet ports, then take it from there...




58. Higher resolution on a Dell E177FPb monitor using modelines in xorg.conf on Debian Testing

Update 24 May 2013: this still works fine on the optiplex (with intel onboard graphics) but when trying it on a different machine with an external nvidia card I couldn't get it to work. There only "xrandr --output VGA-0 --scale 1.1x1.1" worked.

Original post:
I've hooked up my fancy new-ish optiplex 990 to an old Dell E177FPb monitor which I bought back in 2007. For various reasons I've also removed the nvidia quattro graphics card that the optiplex 990 came with -- the main reasons being 1) I hate displayport and _need_ vga and 2) the bios forces you to press 'any key' on each boot if you leave the card in, even though you've configured the OS to use the integrated onboard graphics.

At any rate, hooking my old screen to my dell lead to a less than overwhelming experience -- and querying the 'Displays' setting in gnome showed only two resolution options: 1024x768 and 800x600. Well, I knew for a fact that the maximum resolution should be 1280x1024.

This was a bit of a surprise given that the same xorg.conf had been used together with a fancy widescreen 1920x1080 display -- yet it would not handle a 1280x1024 display? I guess this might say more about my lack of understanding how display drivers work, but whatever.

Well, in the end it turned out to be easy to enable the missing resolution mode.

First, a minimal amount of googling told me that the max resolution was 1280x1024 at 75 Hz.
"Preset Resolution: 1280 x 1024 @ 75 Hz"

Next, using gtf I generated a Modeline line.

gtf 1280 1024 75
Modeline     "1280x1024_75.00" 138.54 1280 1368 1504 1728 1024 1025 1028 1069 -HSync +Vsync

Finally, I then edited the xorg.conf (again, see this post for the entire xorg.conf), changing


Section "Monitor"
Identifier   "Monitor0"
VendorName   "Monitor Vendor"
ModelName    "Monitor Model"
EndSection

to


Section "Monitor"
Identifier   "Monitor0"
VendorName   "Monitor Vendor"
ModelName    "Monitor Model"
Modeline     "1280x1024_75.00" 138.54 1280 1368 1504 1728 1024 1025 1028 1069 -HSync +Vsync
EndSection

Doing startx to start up gnome, followed by selecting Displays, then selecting Resolution: 1280x1024 (5:4) yielded a beautifully satisfying  user experience.

I'm not one to fiddle with xorg.conf, but this time it turned out that the fix was easy once I had figured out what to do.

01 February 2012

57. Making life in linux easier -- Small fixes and tasks

Here's a list over simple fixes and tasks in Debian that I've been running into the past few weeks. I'll be adding to it over time.

Index of the ever-growing list
1. INIT: Id "co" respawning too fast: disabled for 5 minutes
2. Boot into terminal instead of gdm (kdm/xdm etc.)
3. Change the logical name of an ethernet card -- why do I have eth1 and rename2 and how to get eth0 and eth1 instead?
4. Configuring ethernet cards in gnome3/gnome-shell -- can't save changes in network-manager
5. Gnome3/gnome-shell -- Alt+f2 yields "command not found"
6. /etc/hosts keep on being overwritten
7. Getting Leadtek DTV1000s to work in Linux
8. Turning off terminal beep
9. Trouble with apt-get  -- can't do apt-get update
10. Adding and removing pages in a pdf using pdftk
11. Updating the locate database
12. My gateway doesn't play well with sinfo
13. Basic proxy via ssh
14. Using a Compose key to type non-standard characters like å, ä, ö
15. Command not found, did you mean ..? Installing command-not-found
16. apt-listbugs
17. Thunar is the default file manager in spite of me running Gnome!
18. Nautilus recognises compressed files, but doesn't know how to open them
19. Finding out when a package was installed
20. Showing your kernel and debian version
21. Screen dump in the terminal
22. Enable java in chrome
23. Changing element colour in gdis
24. CCSD mercury /lib/libc6.so
25. Daemons...rcconf, sysv-rc-conf and update-rc.d
26. Adjusting your webcam
27. Command line burning of iso
29. USB support in virtualbox
30. Start-up applications in Gnome 3.4
31. Changing pulseaudio volume from the command line


1. INIT: Id "co" respawning too fast: disabled for 5 minutes
References: http://www.linuxquestions.org/questions/fedora-35/init-id-co-respawning-too-fast-disabled-for-5-minutes-736393/ and http://www.linuxquestions.org/questions/linux-newbie-8/reload-inittab-without-reboot-366505/

Instructions: 
Edit /etc/inittab
Find a line saying
co:2345:respawn:/sbin/getty hvc0 9600 linux
and comment it out by prefixing it with a #;

#co:2345:respawn:/sbin/getty hvc0 9600 linux

Run 
sudo init q
to make the changes take effect.

2. Boot into terminal instead of gdm (kdm/xdm etc.)
Instructions:
Method 1:
Edit /etc/default/grub
Change
GRUB_CMDLINE_DEFAULT="quiet splash nomodeset nouveau.modeset=0"
to
GRUB_CMDLINE_DEFAULT="quiet splash text nomodeset nouveau.modeset=0"

(You may obviously not have nomodset etc. in that line. )
IMPORTANT: run
sudo update-grub

to make the changes take effect.

To start up a desktop type startx

3. Change the logical name of an ethernet card -- why do I have eth1 and rename2 and how to get eth0 and eth1 instead?  
Edit /etc/udev/rules.d/70-persistent-net.rules
You'll find lines like this one:
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:e9:90:00", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

You can bind a logical name (NAME="eth0") to a mac address (ATTR{address}=="") here.

NOTE that interfaces handled by network-manager won't show up here. Unless you initialise a network interface in /etc/network/interfaces they will be handled by network-manager.

4. Configuring ethernet cards in gnome3/gnome-shell -- can't save changes in network-manager
If you click on the network icon in gnome3/gnome-shell, then network settings, wired, configure and edit the connection, then hit save, you may find that it won't save the changes. You may even see a black box asking for admin password flash by and disappearing.

There's no real fix -- make sure to start the Network Connections application the 'normal' way instead (top left corner, type in networ... and pick network connections. You'll be able to save your changes now.

5. Gnome3/gnome-shell -- Alt+f2 yields "command not found"
Edit /usr/share/gnome-shell/js/misc/util.js 
Delete all instances of argc e.g. if it say success, argc, argv -- change to success, argv

6. /etc/hosts keep on being overwritten
The culprit is -- no surprise --- network-manager. You can either fight it, or use network-manager to manage your configuration.

My particular case was this: my computer is called tantalum. I don't want tantalum to be associated with 127.0.1.1 or 127.0.0.1 though (mpich2 reasons), but want to associate the host name with the external ip address (192.168.1.102). This is a typical case where you'd edit /etc/hosts and you'd be done. Apart from the fact that the file gets overwritten on each boot.

To force it using network manager, start network-admin in the terminal or using alt+f2, go to Hosts, and remove your hostname from 127.0.1.1 and add it using the desired ip address.

Reading this it seems like it's possible making changes in the configuration files directly. In particular, the option to define unmanaged devices looks interesting.

Network Manager is one of those programs which are great when you need basic functionality from your system, but an absolute pain in the arse when you need to do something non-standard.


7. Getting Leadtek DTV1000s to work in Linux
This is a bit of a non-fix...the card should work out of the box, so to speak.
However, it didn't for me. 

If lspci gives Philips something or other and rev ff rather than e.g. rev 01 as well as MMIO errors, check your BIOS! I kept on getting very little information about my card when doing lspci -vn and it turned out that I had disabled PnP in the BIOS. Once the bios was set to allow the OS to configure PCI devices (Plug-and-play OS), everything worked like a charm.

I put
options saa7134 tuner=48 card=175
in my /etc/modules, but I'm not sure this matters.

Long before discovering that I built and installed the v4l-dvb media build from the git repos,
(Easily done like this:
git clone git://linuxtv.org/media_build.git
cd media_build
./build
)
 and downloaded the firmware packages by Mike Krufky (http://tw1965.myweb.hinet.net/), and spent time reading forum posts (starting with http://forums.whirlpool.net.au/archive/942269). What I'm saying is that I don't THINK you will need to install or compile anything, but you MAY have to. Make sure your BIOS settings are right first though.

Here's lcpci -vvnn for a working leadtek dtv1000s:

01:06.0 Multimedia controller [0480]: Philips Semiconductors SAA7130 Video Broadcast Decoder [1131:7130] (rev 01)
Subsystem: LeadTek Research Inc. WinFast DTV1000S [107d:6655]
Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
Latency: 64 (21000ns min, 8000ns max)
Interrupt: pin A routed to IRQ 19
Region 0: Memory at deeffc00 (32-bit, non-prefetchable) [size=1K]
Capabilities: <access denied>l
Kernel driver in use: saa7134

Here's dmesg|grep saa
    7.213108] saa7130/34: v4l2 driver version 0, 2, 17 loaded
[    7.213383] saa7134 0000:01:06.0: PCI INT A -> Link[LNKC] -> GSI 19 (level, low) -> IRQ 19
[    7.213387] saa7130[0]: found at 0000:01:06.0, rev: 1, irq: 19, latency: 64, mmio: 0xdeeffc00
[    7.213392] saa7130[0]: subsystem: 107d:6655, board: Leadtek Winfast DTV1000S [card=175,autodetected]
[    7.213407] saa7130[0]: board init: gpio is 2020000
[    7.260128] input: saa7134 IR (Leadtek Winfast DTV as /devices/pci0000:00/0000:00:04.0/0000:01:06.0/rc/rc0/input6
[    7.260181] rc0: saa7134 IR (Leadtek Winfast DTV as /devices/pci0000:00/0000:00:04.0/0000:01:06.0/rc/rc0
[    7.412048] saa7130[0]: i2c eeprom 00: 7d 10 55 66 54 20 1c 00 43 43 a9 1c 55 d2 b2 92
[    7.412055] saa7130[0]: i2c eeprom 10: 00 ff 82 0e ff 20 ff ff ff ff ff ff ff ff ff ff
[    7.412060] saa7130[0]: i2c eeprom 20: 01 40 01 01 01 ff 01 03 08 ff 00 8a ff ff ff ff
[    7.412065] saa7130[0]: i2c eeprom 30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412070] saa7130[0]: i2c eeprom 40: ff 35 00 c0 00 10 03 02 ff 04 ff ff ff ff ff ff
[    7.412074] saa7130[0]: i2c eeprom 50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412079] saa7130[0]: i2c eeprom 60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412084] saa7130[0]: i2c eeprom 70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412089] saa7130[0]: i2c eeprom 80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412093] saa7130[0]: i2c eeprom 90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412098] saa7130[0]: i2c eeprom a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412103] saa7130[0]: i2c eeprom b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412108] saa7130[0]: i2c eeprom c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412113] saa7130[0]: i2c eeprom d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412117] saa7130[0]: i2c eeprom e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.412122] saa7130[0]: i2c eeprom f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
[    7.608255] saa7130[0]: registered device video0 [v4l2]
[    7.608280] saa7130[0]: registered device vbi0


8. Turning off terminal beep
To remove immediately:
sudo modprobe -r pcspkr snd_pcsp

To turn off permanently:
create a file called blacklist.conf in /etc/modprobe.d
Put the following in it:
blacklist pcspkr
blacklist snd_pcsp
9. Trouble with apt-get  -- can't do apt-get update
The issue:
On running

sudo apt-get update

you get

Reading package lists... Error!
E: Encountered a section with no Package: header
E: Problem with MergeList /var/lib/apt/lists/192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_contrib_i18n_Translation-en
E: The package lists or status file could not be parsed or opened.
The solution:
First, look in /var/lib/apt/lists

ls /var/lib/apt/lists/ -lah | grep contrib |grep i18n| grep testing

which gives

-rw-r--r-- 1 root root  34K Feb  3 07:01 192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_contrib_i18n_Translation-en
-rw-r--r-- 1 root root 121K Feb  3 07:01 192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_contrib_i18n_Translation-en%5fAU

Then remove the offending file:

sudo rm /var/lib/apt/lists/192.168.1.1:3142_ftp.au.debian.org_debian_dists_testing_contrib_i18n_Translation-en

And do sudo apt-get update again -- it should now work.

If it doesn't then you're lacking bzip2 and should look at this post.

10. Adding and removing pages in a pdf using pdftk
Scenario:
I have a pdf document which I need to sign on the last page. Instead of printing the entire document and scanning it, I print the last page, scan it and replace the last page of the original pdf with it.

How to do:
In my case I have a 27 page document and want to replace pages 25, 26 and 27..

Remove pages 25-27 from original document i.e.keep 1-24:
pdftk original.pdf cat 1-24 output new.pdf

Add new pages 25,26 and 27 which make up signatures.pdf
pdftk cat new.pdf signatures.pdf output final_document

11. Updating the locate database
locate is a good command for finding certain types of files. It seems to be continously, but not immediately, updated.

To force the locate database to update:
sudo updatedb

12. My gateway doesn't play well with sinfo
My gateway is a computer with two eth cards -- one connected to the internet and one to a switch making up a local subnet. All the boxes on the local subnet can see each other's sinfod instances, but not the gateway machine.

Turns out the fix is simple -- change /etc/default/sinfo:
from
#OPTS="${OPTS} --bcastaddress=127.0.0.1"
to
OPTS="${OPTS} --bcastaddress=192.168.1.255"
which is the appropriate broadcast for my subnet.

Sinfo is cool and a 'must' for anyone running a small LAN for computational reasons:

/ 3 nodes, 11 CPUs   total CPU utilization:   2.7% ( 0.351 GHz / 12.800 GHz )
beryllium                     uuuuuusssiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii-------------------------
( 4) mem: 55.6% swap:  0.0%   us:  4.8%    id: 92.7%        me S   8.9   0 chrome     
me S   6.6   0 vmd_LINUXAMD64
     
me S   5.5   0 chrome
     
me S   4.5   0 gnome-shell
     
root R   4.0   0 Xorg

kookaburra                    iiii---------------------------------------------------------------------------------------------------------------------------------------------------------
( 1) mem: 22.9% swap:  0.0%   us:  0.0%                            sy:  0.0%                            ni:  0.0%    wa:  0.0%                            id:100.0%     
me S   0.2   0 sinfo
   
daemon R   0.1  10 sinfod
       
ntp S   0.0   0 ntpd
     
root S   0.0   0 rsyslogd
       
root S   0.0   0 /usr/sbin/apach
tantalum                      iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii( 1) mem: 20.9% swap:  0.0%   us:  0.0%                            sy:  0.0%                            ni:  0.0%                            wa:  0.0%    ;id:100.0%     
me S   0.3   0 conky
       
root S   0.2   0 Xorg
     
me S   0.1   0 gnome-shell
     
me  S   0.1   0 dropbox
     
me S   0.0   0 linphone-3

If you can't see all the boxes on your gateway, change all the LAN boxes to broadcast on 192.168.1.255 (or the appropriate replacement).

13. Basic proxy via ssh
If you have an ssh account on another server you can use it as a proxy

ssh -C -D 9889 me@remote.server.org

-C turns on compression
-D redirects traffic sent to port 9889 to the remote.server.org

Chrome/Chromium use the system settings for the network connection:
To use the proxy for web browsing on gnome 3/gnome-shell, left-click on the connection icon in the top right corner of your desktop (or just go to System Settings), select Network Settings, Click on the tab called Network Proxy, Method: Manual, and set SOCKS host to localhost and port to 9889. You can also change it in Chrome/Chromium -- preferences/proxy which opens the system-wide network settings.


Iceweasel/Firefox by default uses it's own settings:
Edit/Preferences/Network tab/Connections - Settings... -- Select Manual Proxy Configuration, SOCKS hosts: localhost, port 9889.

14. Using a Compose key to type non-standard characters like å, ä, ö
In gnome 3/gnome-shell, open Region and Languages in the System Settings; select the Layout tab. Pick your usual language (e.g. English (US)) and click on options. Expand the Compose Key Position and pick a key to use as the Compose Key, e.g. right alt or the windows symbol key.

Now you can type fancy European characters with a lot more ease -- for a list over key sequences, look here.

Two example -- to type É first touch the compose key (don't hold it down), then ', then shift+E. For Ã¥ do compose, o, a. For € do compose, =, c. For ö, do compose, ", o.

15. Command not found, did you mean ..? Installing command-not-found
On a basic install of debian, typing nfs gets you

me@lithium:~$ nfs
-bash: nfs: command not found
Linux can do better than that:

Install command-not-found
sudo apt-get install command-not-found
sudo update-command-not-found

Restart the shell (or log in and out)

Now, when typing nfs you get:
me@lithium:~$ nfs
No command 'nfs' found, did you mean:
 Command 'lfs' from package 'lustre-utils' (main)
 Command 'xfs' from package 'xfs' (main)
 Command 'knfs' from package 'openafs-client' (main)
 Command 'nns' from package 'tcllib' (main)
 Command 'ns' from package 'ns2' (main)
 Command 'fs' from package 'openafs-client' (main)
 Command 'zfs' from package 'zfs-fuse' (main)
 Command 'hfs' from package 'hfsutils-tcltk' (main)
nfs: command not found

16. apt-listbugs
A useful tool for catching problematic packages when you upgrade/dist-upgrade is to use apt-listbugs. It gets invoked automatically when you run sudo apt-get...

Install by
sudo apt-get install apt-listbugs

For an example of it in action, see http://www.worksinmymind.com/blog/?p=1125

17. Thunar is the default file manager in spite of me running Gnome!
You can either remove thunar -- which you probably got through install xfce4 -- or you can edit .config/xfc4/helpers.rc


me@niobium:~$ cat .config/xfce4/helpers.rc
MailReader=evolution
#FileManager=Thunar
FileManager=nautilus
WebBrowser=google-chrome

18. Nautilus recognises compressed files, but doesn't know how to open them
Install file-roller. You may want to install additional packages as per aptitude show file-roller:
Suggests: arj, binutils, cpio, lha, lzip, lzma, lzop, ncompress, rpm2cpio, rzip, sharutils, unace, unalz, unrar |
          p7zip-rar, unzip, xz-utils, zip, zoo
19. Finding out when a package was installed
Look here.

Listing all packages according to time, most recent last.
ls /var/lib/dpkg/info/*.list -lrth| grep "info/lib"
Looking for a specific subset of packages
ls /var/lib/dpkg/info/*.list -lrth| grep "info/lib"
20. Showing your kernel and debian version
Someone searched for www.google.co.kr — linux debian version check and ended up on this blog. Well, here are the answers:
me@beryllium:~$ uname -a
Linux beryllium 3.2.0-1-amd64 #1 SMP Sun Feb 5 15:17:15 UTC 2012 x86_64 GNU/Linux
me@beryllium:~$ cat /etc/debian_version
wheezy/sid

21. Screen dump in the terminal
Method 1. Works in the 'true' terminals i.e. ttyX:
If you want to save what is already on the screen into a text file, do
sudo cat /dev/vcsX > screendump.txt
where X is the number of your terminal (e.g. tty1, tty2 etc.)

This method does not seem to add linebreaks -- instead it presumes that you're using a standard 80 char terminal.


Method 2. Using framebuffer
First check if you are using the framebuffer
ls /dev/fb0
If so, install fbcat
sudo apt-get install fbcat

Get a screen dump by running
fbgrab screendump.png




22. Enable java in chrome
Java has always been tricky. Sometimes icedtea-plugin has worked, sometimes it hasn't. At the moment it works:
sudo apt-get install icedtea-plugin

update-alternatives: using /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws to provide /usr/bin/javaws (javaws) in auto mode.update-alternatives: using /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/itweb-settings to provide /usr/bin/itweb-settings (itweb-settings) in auto mode.
Not sure about the java-6-openjdk-amd64 since I actually have openjdk-7 installed and not 6. Try installing openjdk7-7-jdk first.


i A openjdk-6-jre                   - OpenJDK Java runtime, using Hotspot JIT   
i A openjdk-6-jre-headless          - OpenJDK Java runtime, using Hotspot JIT (h
i A openjdk-6-jre-lib               - OpenJDK Java runtime (architecture indepen
i   openjdk-7-jdk                   - OpenJDK Development Kit (JDK)             
i   openjdk-7-jre                   - OpenJDK Java runtime, using Hotspot JIT   
i A openjdk-7-jre-headless          - OpenJDK Java runtime, using Hotspot JIT (h
i A openjdk-7-jre-lib               - OpenJDK Java runtime (architecture indepent

23. Changing element colour in gdis
GDIS is, in my opinion, the best linux program for generating povray files from crystallographic data. Mainly this is due to the number of different representations which can be selected: from ball-and-stick to polyhedral to surface -- and it allows mixing different representations in  the same molecule, which is what sets it apart.

Long story short, in order to change the default element colours you have to manually edit /usr/share/gdis/gdis.elements

Each element is contained between a %gdis_elemen and and a %gdis_end tag. The colour is given in RGB code ranging from 0 to 65k. To look up RGB codes, look e.g. here http://www.tayloredmktg.com/rgb/.

%gdis_elem
symbol: Na
  name: Sodium
number: 11
weight: 22.989799
  cova: 0.970000
   vdw: 1.450000
charge: 1.000000
colour: 30000 52600 60600
%gdis_end
You can also change the covalent and van der Waal radii here -- these are used to determine bonding  so if you have too many or not enough bonds in the molecule, you can fiddle with this.

As an aside, I'm having problems in general with converting .tga and .png to good-looking eps. This is the best I've got so far and uses inkscape. Convert and GIMP don't yield results which are as good.

povray +W400 +H400 $1.pov +A
inkscape --verb FileSave --verb FileClose --export-eps=$1.eps $1.png 

Odd though that povray can't directly output vector-based image formats.
Edit: Here are the technical reasons why we're stuck with bitmap formats: http://news.povray.org/povray.pov4.discussion.general/message/%3C4a79fd58%241%40news.povray.org%3E/#%3C4a79fd58%241%40news.povray.org%3E

24. CCSD mercury /lib/libc.so.6

Mercury is a program for displaying crystal structures from the CCSD.
./mercury 
Using native OpenGL
Warning: mercury requires /lib/libc.so.6 but not found

sudo ln -s /lib/x86_64-linux-gnu/libc.so.6 /lib/libc.so.6
ls /lib/libc.so.6 -lah
/lib/libc.so.6 -> /lib/x86_64-linux-gnu/libc.so.6
./mercury 
Using native OpenGL
INFO: The environment variable CSDHOME is not set.
You can set CSDHOME by including
export CSDHOME=/home/me/mercury
(use the correct path)
in your ~/.bashrc

25. Daemons...rcconf and update-rc.d
You can easily enable and disable services to load on boot by using rcconf, which is an curses type tool.

Or use sysv-rc-conf:


Alternative, use update-rc.d which doesn't faff around with any gui.
Usage is described here.
To remove a daemon:
update-rc.d -f apt-cacher-ng remove
To add a daemon:
update-rc.d apt-cacher-ng defaults

If you're more adventurous:
update-rc.d apt-cacher-ng start 20 2 3 4 5 . stop 20 0 1 6 .

where 20 is a two-digit seq code used by init to decide which order to run the script in, and numbers between 1 and 9 and S are the run levels. More information in /etc/inittab

Here: "Default Debian installation does not make any difference between runlevels 2-5. You may customize them to your liking. Runlevels S (single) and 1 are used for maintenance. They start services minimally to avoid possible problems." 0 is halt and 6 is reboot.



26. Adjusting your webcam
I've had problems with webcam images being overly dark -- trying to adjust the image with cheese leads to nothing.

v4l2ucp, which is in the debian repos, however, is a good GUI-based configuration tool which allows you to adjust most things, including, importantly, light sensitivity rather than just brightness.
v4l2ucp on a much-too-small screen
27. Command line burning of iso
sudo apt-get install burn
sudo burn -I -n debian.iso
Simple as that.

For burning audio cds from mp3 files I use a slightly different approach:

sudo apt-get install brasero-cdrkit mpg123
for i in *.mp3; do mpg123 --rate 44100 --stereo --buffer 3072 --resync -w "`basename "$i" .mp3`".wav "$i"; done
Then name the files in a way that they are listed in desired play order.

ls /dev/cdr
cdrom1  cdrw1
 wodim -v -pad speed=1 dev=/dev/cdrw1 -dao -swab *.wav

burns.

28. Finding a file in a package
Two methods:
dpkg --search libglib
apt-file search libglib
(apt-file update before first use)

29. USB support in virtualbox
If you keep getting errors along the lines of:
Failed to access the USB subsystem
and
NS_ERROR_FAILURE
in virtualbox when trying to enable USB devices, make sure that you've added yourself to the vboxusers group in /etc/group. You'll need to reinit before it takes effect (e.g. by rebooting)

30. Startup applications in gnome 3.4
In the past I've always used gnome-session-properties, but it's a hit and miss affair at the moment. So it would be nice with an alternative approach.

According to this: http://ubuntuforums.org/showthread.php?t=1992296
anything which is found in /etc/xdg/autostart will be automatically executed, e.g.

cat /etc/xdg/autostart/guake.desktop 
[Desktop Entry]
Name=Guake Terminal
Name[pt]=Guake Terminal
Name[pt_BR]=Guake Terminal
Comment=Use the command line in a Quake-like terminal
Comment[pt]=Utilizar a linha de comando em um terminal estilo Quake
Comment[pt_BR]=Utilizar a linha de comando em um terminal estilo Quake
TryExec=guake
Exec=guake
Icon=/usr/share/pixmaps/guake/guake.png
Type=Application
Categories=GNOME;GTK;Utility;TerminalEmulator;
StartupNotify=true
X-GNOME-Autostart-enabled=false
Also, it's been suggested that there's a bug in guake: http://motorscript.com/guake-patch-to-fix-focus-on-gnome/
Guake starts well for me on my laptop, but not on my nvidia boxes.

31. Changing pulseaudio volume from the command line
Copy this script (https://gist.github.com/814634) and make executable. Requires ruby.
Invoke using the arguments up, down, toggle.