Wednesday, December 15, 2010

How to chroot bind9 in Debian

Here are few simple steps to chroot bind9 in debian squeeze.
#!/bin/bash
/etc/init.d/bind9 stop
mkdir -p /var/chroot/bind9/{etc,dev,var/cache/bind,var/run/bind/run}
chown -R bind:bind /var/chroot/bind9/var/*
mknod /var/chroot/bind9/dev/null c 1 3
mknod /var/chroot/bind9/dev/random c 1 8
chmod 666 /var/chroot/bind9/dev/{null,random}
mv /etc/bind /var/chroot/bind9/etc
ln -s /var/chroot/bind9/etc/bind /etc/bind
chown -R bind:bind /etc/bind/*
echo "\$AddUnixListenSocket /var/chroot/bind9/dev/log" > /etc/rsyslog.d/bind-chroot.conf
Switch bind9 to use the chroot (file /etc/default/bind9):
OPTIONS="-u bind -t /var/chroot/bind9"
Finally restart rsyslogd and start bind9.
/etc/init.d/rsyslog restart ; /etc/init.d/bind9 start
You can download script from here.

Debian simple DNS server setup

We are going setup a simple Debian DNS server for local purpose using bind9.
apt-get install -y rsyslog bind9 bind9-doc dnsutils
Once the server installed let our system know which dns server to use (a one we just installed), ensure that 127.0.0.1 is the first nameserver in the list (file /etc/resolv.conf):
nameserver 127.0.0.1
In case you do no need the server to listen on ipv6 set the following option (file /etc/bind/named.conf.options):
listen-on-v6 { none; };
Restart bind9 daemon:
/etc/init.d/bind9 restart
and verify with:
root@ns1:~# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 192.168.10.2:53         0.0.0.0:*               LISTEN      816/named       
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      816/named       
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      816/named       
udp        0      0 192.168.10.2:53         0.0.0.0:*                           816/named       
udp        0      0 127.0.0.1:53            0.0.0.0:*                           816/named       
That pretty it, let ensure its working. First we need install dnsutils package that comes with dig command, so here we go:
root@ns1:~# dig debian.org
; <<>> DiG 9.7.2-P3 <<>> debian.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64434
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 3, ADDITIONAL: 3

;; QUESTION SECTION:
;debian.org.   IN A

;; ANSWER SECTION:
debian.org.  3600 IN A 128.31.0.51
debian.org.  3600 IN A 206.12.19.7

;; AUTHORITY SECTION:
debian.org.  28606 IN NS ns2.debian.org.
debian.org.  28606 IN NS ns4.debian.com.
debian.org.  28606 IN NS ns1.debian.org.

;; ADDITIONAL SECTION:
ns1.debian.org.  28606 IN AAAA 2607:f8f0:610:4000:214:38ff:feee:b65a
ns4.debian.com.  28606 IN A 194.177.211.209
ns4.debian.com.  28606 IN AAAA 2001:648:2ffc:deb::10:10

;; Query time: 96 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Dec 15 21:47:12 2010
;; MSG SIZE  rcvd: 196
Notice the server responded to our request was 127.0.0.1. Read more here and here. Consider chroot your dns server, details here.

How to solve eth0 missing in VirtualBox

Suppose you setup a linux virtual machine in VirtualBox and once you clone that hard disk and attach to a new virtual machine you notice that eth0 is not available. The problem is related to fact that since the MAC address of network adapter has changed (you created a new virtual machine) kernel has reconfigured it to be used by next available name, e.g. eth1. So what you need is simply open file /etc/udev/rules.d/70-persistent-net.rules in your favorite editor and remove a line that uses currently eth0 and change the line with NAME="eth1" to NAME="eth0". Here is an example:
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", \
ATTR{address}=="08:00:27:43:0b:0f", ATTR{dev_id}=="0x0", \
ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
Probably simplest way to do this:
echo > /etc/udev/rules.d/70-persistent-net.rules
reboot

How to disable ipv6 in Debian

Here are simple steps to disable ipv6 in Debian:
  1. Comment out anything related to ipv6 in /etc/hosts
  2. SSH. Ensure AddressFamily inet is set in /etc/ssh/sshd_config. Restart ssh.
  3. BIND. Ensure listen-on-v6 { none; }; in /etc/bind/named.conf.options. Restart bind9.
  4. NTP. Ensure -4 option is set in /etc/default/ntp (e.g. NTPD_OPTS='-4 -g'). Restart ntp.
  5. APACHE2. Ensure Listen 0.0.0.0:80 in /etc/apache2/ports.conf file. Restart apache2.
  6. RPCBIND (rpc.statd, rpc.mountd). Comment out the appropriate entries in /etc/netconfig:
    udp        tpi_clts      v     inet     udp     - -
    tcp        tpi_cots_ord  v     inet     tcp     - -
    #udp6       tpi_clts      v     inet6    udp    - -
    #tcp6       tpi_cots_ord  v     inet6    tcp    - -
    rawip      tpi_raw       -     inet      -      - -
    local      tpi_cots_ord  -     loopback  -      - -
    unix       tpi_cots_ord  -     loopback  -      - -
    
  7. PostgreSQL 9. Ensure ipv4 in listen_addresses (file /etc/postgresql/9.1/main/postgresql.conf):
    # - Connection Settings
    listen_addresses = '0.0.0.0'
    
    Comment out lines related to ipv6 (file /etc/postgresql/9.1/main/pg_hba.conf):
    # IPv6 local connections:
    #host  all     all     ::1/128   md5
    
    Restart postgresql.
  8. Disable ipv6 in kernel:
    echo net.ipv6.conf.all.disable_ipv6=1 \
    > /etc/sysctl.d/disableipv6.conf
    
  9. Disable ipv6 in kernel modules (file /etc/modprobe.d/aliases.conf):
    # alias net-pf-10 ipv6
    alias net-pf-10 off
    alias ipv6 off
    
The next time the system boots it will have ipv6 disabled. Let verify it with:
netstat -tunlp
Here is a sample output:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 192.168.10.2:53         0.0.0.0:*               LISTEN      895/named       
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      895/named       
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      734/sshd        
tcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTEN      895/named       
udp        0      0 192.168.10.2:53         0.0.0.0:*                           895/named       
udp        0      0 127.0.0.1:53            0.0.0.0:*                           895/named         
Read more about ipv6 here.

Tuesday, December 14, 2010

How to lock console in Debian

There is an easy way to lock your console session in Linux. Just install vlock:
apt-get install vlock
Once installed, issue command vlock, here is what you will see:
This TTY is now locked.

Please press [ENTER] to unlock.
Read more about vlock here.