Some curl tips

  • Show headers with -I and change request type with -X. e.g.
curl -I -X DELETE  http://localhost/blah
  • To add a header in the outgoing request, use -H:
curl --header "X-MyHeader: 123" www.google.com
  • Follow redirects with -l
  • Disable security check with -k
  • Send content with -d:
curl -X POST --header "Content-Type: application/json" -d '{"test": true}' http://localhost/blah

iptables port forwarding

Use case: make tomcat on port 8443 listen on port 443.

sudo iptables -A PREROUTING -t nat \
  -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

This will forward all traffic coming in on port 443 to the tomcat server listening on 8443.

(picked from here: https://mihail.stoynov.com/2011/04/04/howto-start-tomcat-on-port-80-without-root-privileges/)

To view, the usual -L and -F won’t show anything. Instead, use:

iptables -L -t nat
iptables -F -t nat

Python UDP Client and Server

I use this often, so I’m pasting the code here as a reference.

UDP Client

From PyMOTW :

import socket
import sys

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

server_address = ('192.168.0.100', 8080)
message = 'This is the message.  It will be repeated.'

try:

    # Send data
    print >>sys.stderr, 'sending "%s"' % message
    sent = sock.sendto(message, server_address)

    # Receive response
    print >>sys.stderr, 'waiting to receive'
    data, server = sock.recvfrom(4096)
    print >>sys.stderr, 'received "%s"' % data

finally:
    print >>sys.stderr, 'closing socket'
    sock.close()

UDP Server

From PyMOTW :

import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Bind the socket to the port
server_address = ('localhost', 10000)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
while True:
    print >>sys.stderr, '\nwaiting to receive message'
    data, address = sock.recvfrom(4096)

    print >>sys.stderr, 'received %s bytes from %s' % (len(data), address)
    print >>sys.stderr, data

    if data:
        sent = sock.sendto(data, address)
        print >>sys.stderr, 'sent %s bytes back to %s' % (sent, address)

IPv6 on Slackware HOWTO

Okay, here’s a quick and easy HOWTO on getting IPv6 running on your Linux box. I’m using a stock Slackware 11 box, so this should work pretty much the same anywhere else (unless you already have it enabled).

Check whether or not your kernel already has the IPv6 modules loaded:

/sbin/ifconfig -a | grep inet6

Load the module and see the results:

modprobe ipv6

You should now be able to ping to localhost:

ping6 ::1
PING ::1(::1) 56 data bytes
64 bytes from ::1: icmp_seq=1 ttl=64 time=0.095 ms
64 bytes from ::1: icmp_seq=2 ttl=64 time=0.074 ms
64 bytes from ::1: icmp_seq=3 ttl=64 time=0.071 ms

If you’re behind a NAT, your best option is probably in getting a tunneling client that’ll encapsulate your v6 packets in v4 and then send them across. I found a very nice one: Freenet6’s Gateway6 client. Download the package and install it. Installation is as easy as a gmake all and a gmake install. The executable is called gw6c. A config file (gw6c.conf) is also needed.

I haven’t registered with Freenet6 yet, so I connect as an anonymous user, and an IPv6 address is given to me from a pool. I went through the guide included in the package, but I didn’t have to change a thing in the config file, and the defaults allowed me to connect to their broker.

You’re all set now! Check out the Kame website; if you see a dancing turtle, you’re all done! Just in case you’re wondering about existing IPv4 websites and such, don’t worry: Both A and AAAA DNS queries are made, so if a website is not IPv6 enabled, you’ll still be able to access it without any problems.

Further on..

This comprehensive HOWTO really gives you bucketloads of information in case you’re interested.
If you’re happy with the changes and want to make them permanent, you might want to add the modprobe ipv6 line in your /etc/rc.d/rc.modules file, and another rc file in /etc/rc.d to start your client.