Something New Continuing Education through Self Motivation

17Nov/090

Iptables : Remove an entry

Sorry it's been a while.

You can either delete by number or by recreating the rule. "iptables -D
INPUT 3" will remove the 3rd (counting from 1) rule. Or "iptables -D
INPUT -s 65.75.152.40 -j DROP" will remove the corresponding entry
independent of location. The rules must match exactly though or you'll
get a "Bad rule" error.

http://www.plug.org/pipermail/plug/2004-November/010606.html
http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/s1-iptables-options.html
http://netfilter.org/documentation/HOWTO/packet-filtering-HOWTO-7.html
16Nov/090

xargs and find

xargs is a command on Unix and most Unix-like operating systems. It is useful when one wants to pass a large number of arguments to a command. Until Linux kernel 2.6.23, arbitrarily long lists of parameters could not be passed to a command [1], so xargs will break the list of arguments into sublists small enough to be acceptable.

Additional Reading:

http://en.wikipedia.org/wiki/Xargs

http://www.softpanorama.org/Tools/xargs.shtml

http://www.linuxplanet.com/linuxplanet/tutorials/6522/1/

Filed under: linux, scripts No Comments
3Nov/090

tail -f multiple files

Pass more than one filename to tail -f and it will follow each file and let you know when one changes.

daniel@mycomputer:~$ tail -f /var/log/dmesg /var/log/kern.log
==> /var/log/dmesg <==
[   14.951256] type=1505 audit(1256945274.318:9): operation="profile_load" name="/usr/sbin/tcpdump" name2="default" pid=2001
[   16.052417] e1000e 0000:00:19.0: irq 2300 for MSI/MSI-X
[   16.108300] e1000e 0000:00:19.0: irq 2300 for MSI/MSI-X
[   16.108533] ADDRCONF(NETDEV_UP): eth0: link is not ready
[   17.572692] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   17.572694] Bluetooth: BNEP filters: protocol multicast
[   17.578508] Bridge firewalling registered
[   18.272754] 0000:00:19.0: eth0: Link is Up 100 Mbps Full Duplex, Flow Control: None
[   18.272757] 0000:00:19.0: eth0: 10/100 speed: disabling TSO
[   18.272906] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

==> /var/log/kern.log <==
Nov  2 09:39:21 mycomputer kernel: [231116.479553] [drm] Resetting GPU
Nov  2 09:39:21 mycomputer kernel: [231116.479608] [drm] writeback test succeeded in 1 usecs
Nov  2 09:39:25 mycomputer kernel: [231120.406627] CPU0 attaching NULL sched-domain.
Nov  2 09:39:25 mycomputer kernel: [231120.406630] CPU1 attaching NULL sched-domain.
Nov  2 09:39:25 mycomputer kernel: [231120.407377] CPU0 attaching sched-domain:

Filed under: linux No Comments
2Nov/090

Bash Numeric Comparison

Do not use > or < when comparing numbers in BASH. It doesn't work. It tries to redirect output instead of performing the comparison. Use -lt or -gt instead.

Additional Reading:

http://fvue.nl/wiki/Bash:_Numeric_comparison

http://tldp.org/LDP/abs/html/

Filed under: linux, scripts No Comments
21Oct/090

linux iptables port forwarding (PAT)

# Forward an external port to a different internal port on a NAT'd IP
# 1.2.3.4 is the Linux WAN IP
# 10029 is the opened WAN port on the Linux Router
# 192.168.0.12:22 is the private IP and port number to forward port 10029 traffic to
#
iptables -I PREROUTING -t nat -p tcp -d 1.2.3.4 --dport 10029 -j DNAT --to 192.168.0.12:22
iptables -I POSTROUTING -t nat -p tcp -s 192.168.0.12 --sport 22 -j SNAT --to 1.2.3.4:10029
iptables -I OUTPUT -t nat -p tcp -d 1.2.3.4 --dport 10029 -j DNAT --to 192.168.0.12:22
iptables -I INPUT -p tcp -d 192.168.0.12 --dport 22 -j ACCEPT
iptables -I FORWARD -p tcp -d 192.168.0.12 --dport 22 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.0.12 --sport 22 -j ACCEPT

Additional Reading:

http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch14_:_Linux_Firewalls_Using_iptables

19Oct/090

ipip tunnels in linux

Additional Reading:

http://www.linuxfoundation.org/en/Net:Tunneling

18Oct/090

wpa encryption and bridge-utils

As far as I can tell, my wireless NICs do not allow bridging to happen alongside WPA encryption. Something about how frames leaving the radio have to have spoofed MACs when they come from the bridge does not work with wpa_supplicant.

I just want a wireless bridge with WPA. I tried this:

<get wlan0 associated w/ encryption>

brctl addbr br0

brctl addif br0 eth0

brctl addif br0 wlan0

<association via wpa_supplicat immediately drops and fails to re-auth>

16Oct/090

There are many ways to grab a column

There are lots of utilities available when writing scripts to parse various data. A few of them can perform the same tasks. Here we will look at awk, colrm, and cut, and look at how they can all grab columns of data. I'll use 'ps aux' as the data source.

daniel@twilight:~$ ps aux|grep apache
root      5504  0.0  1.0  28092 11372 ?        Ss   Oct11   0:04 /usr/sbin/apache2 -k start
www-data 14227  0.0  2.4  44076 25736 ?        S    Oct14   1:33 /usr/sbin/apache2 -k start
www-data 14695  0.0  2.2  41644 23448 ?        S    Oct14   1:14 /usr/sbin/apache2 -k start
www-data 15563  0.0  2.5  44864 26572 ?        S    Oct14   1:16 /usr/sbin/apache2 -k start
www-data 18452  0.0  2.3  42780 24524 ?        S    Oct15   1:12 /usr/sbin/apache2 -k start
www-data 18770  0.0  2.1  41036 22456 ?        S    Oct15   0:46 /usr/sbin/apache2 -k start
www-data 18836  0.0  1.9  38520 20176 ?        S    Oct15   0:46 /usr/sbin/apache2 -k start
www-data 19174  0.0  1.8  37712 19080 ?        S    Oct15   0:47 /usr/sbin/apache2 -k start
www-data 20953  0.0  2.2  41152 22868 ?        S    05:45   0:16 /usr/sbin/apache2 -k start
www-data 21882  0.1  1.4  34580 14612 ?        S    11:42   0:00 /usr/sbin/apache2 -k start
www-data 21887  0.1  1.1  32112 12200 ?        S    11:43   0:00 /usr/sbin/apache2 -k start
daniel   21929  0.0  0.0   3008   756 pts/0    R+   11:47   0:00 grep apache

daniel@twilight:~$ ps aux | grep apache | awk '{print $1}'
root
www-data
www-data
www-data
www-data
www-data
www-data
www-data
www-data
www-data
www-data
daniel

daniel@twilight:~$ ps aux | grep apache | colrm 10
root
www-data
www-data
www-data
www-data
www-data
www-data
www-data
www-data
www-data
www-data
daniel

daniel@twilight:~$ ps aux | grep apache | cut -d" " -f1
root
www-data
www-data
www-data
www-data
www-data
www-data
www-data
www-data
www-data
www-data
daniel

Additional Reading:

http://www.shell-fu.org/lister.php?tag=colrm

http://linux.die.net/man/1/colrm

http://www.grymoire.com/Unix/Awk.html

http://sparky.rice.edu/awk.html

http://lowfatlinux.com/linux-columns-cut.html

http://www.computerhope.com/unix/ucut.htm

Filed under: linux No Comments
15Oct/090

sed edit files in place

Suppose you want to change 'ENABLED="false"' to true in one of the various /etc/default configuration files in debian. You would probably use sed if you wanted to make this change in lots of places. By default sed just dumps output to STDOUT. To directly edit a file with sed, you either have to edit a file, save the changes elsewhere, and move the changes back to the original file. Or, you can use -i with sed for 'edit files in place.'

Old and busted:

sed 's/2006/2007/g' oldfile > tmpfile ; mv tmpfile oldfile

New hotness:

sed -i 's/2006/2007/g' file

Additional reading for sed:

http://www.grymoire.com/Unix/Sed.html

Filed under: linux No Comments
   

tags

categories

Meta