Showing posts with label Networking. Show all posts
Showing posts with label Networking. Show all posts

Friday, May 11, 2012

OpenBSD - Check hosts alive


#!/bin/sh


# Check all hosts within the network
# BSD license


PING=/sbin/ping
SEQ=gseq


NET=192.168.2
ME=192.168.0.2


i=1;
while [ $i -le 254 ] ;
do
  $PING -v -D -s 8 -t 1 -w 1 -c 1 -I $ME $NET.$i 1>/dev/null
  printf "$?"
  i=`expr $i + 1` ;
done


printf "\n"

Thanks to this site [1] for the while loop

[1] http://www.linuxmisc.com/27-linux-on-alpha/9fdb61f03bee119e.htm

--
  = ^ . ^ =


Wednesday, May 9, 2012

Round Robin DNS redirect in OpenBSD

Redirect all dns requests to a pool of trusted DNS servers (in this case OpenDNS)

Configuration in /etc/pf.conf

dns_servers = "{ 208.67.222.222 208.67.220.220 }"
pass in quick on $inside_if proto udp from <allowed> to any port 53 rdr-to $dns_servers round-robin 

You might also want to add sticky-address to keep asking to one dns server [1] (not my case)

The result when analyzing on the internal interface

# tcpdump -ni rtw0 'port 53 and host ( 8.8.8.8 )'
17:44:46.295443 192.168.127.36.37796 > 8.8.8.8.53: 22244+ A? toneji.to. (31)
17:44:46.384365 8.8.8.8.53 > 192.168.127.36.37796: 22244 1/0/0 A 67.215.65.132 (47)

The result when analyzing on the external interface

# tcpdump -ni xl0 'port 53 and host ( 208.67.220.220 or 208.67.222.222 )'
17:44:46.295561 10.0.2.2.59847 > 208.67.220.220.53: 22244+ A? toneji.to. (31)
17:44:46.384302 208.67.220.220.53 > 10.0.2.2.59847: 22244 1/0/0 A 67.215.65.132 (47) (DF)

This means that *any* DNS request will be forwarded to our trusted DNS servers (Thanks OpenDNS)

References:

[1]  http://www.openbsd.org/faq/pf/pools.html

--
  = ^ . ^ =

Wednesday, March 14, 2012

show my ip address


#!/bin/sh

IP=/bin/ip
SED=/bin/sed
CUT=/usr/bin/cut

IF=en0

if [ ! -z ${1} ]
then
  IF=${1}
fi

$IP addr show dev $IF | $SED -n 3p | $SED -e 's/\ \+/\ /g' -e 's/\/.*$//g' | $CUT -d ' ' -f 3

--
  = ^ . ^ =

Monday, March 5, 2012

IPv4 and IPv6 SOCKS proxy

$ cat Makefile
XTERM=/usr/bin/xterm
SSH=/usr/bin/ssh
GEOMETRY=169x39-0-0
IPv6_LOCALHOST=::1
PROXY_PORT=1080
SSH_PORT?=22
IPv4_PROXY=127.128.129.130
IPv6_PROXY=${IPv6_LOCALHOST}
IPv4_REMOTE?=127.126.125.124
IPv6_REMOTE=${IPv6_LOCALHOST}
IPv4_BIND=127.127.127.127
IPv6_BIND=${IPv6_LOCALHOST}

proxy:
        ${XTERM} -geometry ${GEOMETRY} -iconic -T "IPv4 proxy" \
          -e ${SSH} -v -x -n -N -b $(IPv4_BIND) -p ${SSH_PORT} \
          -D ${IPv4_PROXY}:${PROXY_PORT} ${IPv4_REMOTE} &
        ${XTERM} -geometry ${GEOMETRY} -iconic -T "IPv6 proxy" \
         -e ${SSH} -v -x -n -N -b $(IPv6_BIND) -p ${SSH_PORT} \
         -D [${IPv6_PROXY}]:${PROXY_PORT} ${IPv6_REMOTE} &

$ make proxy

--
  = ^ . ^ =

Tuesday, September 27, 2011

Sep 27th 2011 - Transfer data between virtual machine and host without network

Today I needed to transfer data between a virtual machine and the host.

The main problem was the lack of networking support in MINIX v3.1.0 (the virtual machine) so I could not scp or ftp anything between the systems.

I came to rescue the day with the idea of a special sneakernet between the virtual machine and the host.

On the host

  • Create the floppy image on the host.

    % dd if=/dev/zero of=floppy.img bs=1024 count=1440


  • Attach the floppy image to the virtual machine.

    The process depends on the virtualization software so is left as exercise to the reader.


On the virtual machine

  • cd to the data (let's call it payload, shall we?.

    $ cd /home/tonejito/payload


  • tar the relevant files into the floppy device (/dev/fd0)

    $ tar cvvf /dev/fd0 file file file ...


On the host

  • Detach the floppy image from the virtual machine

    Another exercise left to the reader

  • Extract the files
    % tar xvvf floppy.img

  • List the contents

    % ls
    floppy.img file file file



That's all