Tagged: TCP/IP

Backup a system to a remote location using ‘netcat’ and ‘tar’

I use to say “backup is only for wimps”. But to be honest, I do backups. And I even store the backup media in a save place.

To get the data onto a backup device and put that one to a save place, sometimes you have to write the backup over the network.

netcat or nc, the swiss army knife of networking is a big help for that.

On the remote system, where you want to write the backup start netcat:

nc -l -p 12345 > /var/backup/name-of -the-backup-2010-08-18.tgz
  • -l means listen
  • -p <number> is the port, where nc listens.

On the system you want to backup  you can exclude some directories, like /proc and /sys from being backed up. So run:

echo "./proc
./sys
./tmp" > /tmp/X

Now it is time to start the backup:

cd /
tar -X /tmp/X -czpf - . | nc 11.12.13.14 12345

So you cd into the root directory, exclude the files listed in /tmp/X, write the backup to STDOUT  and backup everything under the current directory. The backup is done relative.

Of course, you could use a backup command like tar -czpf – /,  but then the backup is done absolute. You realize the advantage of doing relative backups, when you want to restore the backup into a directory. With an absolute backup everything is written back to the original location.

IPv6 connection with Fortigate and xDSL

The IPv6 support of Fortigate is very advanced. Unfortunately Fortigate does not support PPPoe with IPv6, because this is a legacy protocol. If you have a DSL connection it does work with IPv4, but not with IPv6. The workaround is: Connect yourself with IPv4 and PPPoe and request from a tunnel provider like www.sixxs.net a tunnel and later a IPv6 subnet.

The configuration on the Fortigate for the sit-tunnel looks like this:

config system sit-tunnel
edit "sixxs-tun"
    set destination 12.34.56.78
    set interface wan1
    set ip6 2001:dead:babe:c5::2/64
    set source 98.76.54.32
end
config system interface
edit "sixxs-tun"
    config ipv6
        set ip6-allowaccess ping
    end
end
config router static6
edit 1
    set device "sixxs-tun"
end

The IP address 12.34.56.78 is the remote tunnel address of your POP.

The IP address 98.76.54.32 is the IP address of your external IPv4 interface.

The IP address 2001:dead:babe:c5::2/64 is the IPv6 address, you got from your tunnel provider.

Now you can use the interface sixxs-tun as your IPv6 connection and gateway.

TCP/IP packet sniffer

Sometimes you need a powerful sniffer on your system. Every Mac and every Linux system got it. You just have to use it.

tcpdump

The only thing you have to know, are a few flags.

  • -i en0 : Listen on this interface.
  • -n : Don’t resolve hostnames.
  • -nn : Don’t resolve hostnames or port names.
  • -X : Show the contents in both hex and ASCII.
  • -XX : Same as -X, but also shows the ethernet header.
  • -v, -vv, -vvv : Increase the amount of packet information you get back.
  • -c : Get n packets and then stop.
  • -S : Print absolute sequence numbers.
  • -e : Get the ethernet header as well.
  • -q : Show less protocol information.
  • -E : Decrypt IPSEC traffic by providing an encryption key.
  • -s : Set the snaplength, i.e. the amount of data that is being captured in bytes

Example:

If you just want to see some traffic on the interface:

tcpdump -ni en0

If you want get a lot of information:

tcpdump -i en0 -nnvvvXSs 1514

Of course there are some other options. You can record the traffic into a file, read it from a file. You can also set filters on the command line to get only specific packets.

tcpdump -i en1 -nnvvS tcp and src 10.0.5.1 and dst port 5222

Network grep “ngrep”

Sometimes it is very practical to use grep, to find a specific regular expression in some files. It would also be very practical to have the grep functionality on the network. This feature is available.

Download ngrep. The package to get is ngrep-1.45.tar.bz2.

To get it to work on a mac do:

tar xvjf ngrep-1.45.tar.bz2
cd ngrep-1.45
./configure --with-pcap-includes=/usr/include --prefix=/usr/local
make
sudo make install

To read the manual page you can run

man ngrep

Now run ngrep itself run

sudo ngrep  <expression to find> <pcap filter expression>

<pcap filter expression> is used the same way as in tcdpdump.