#!/usr/bin/env python # for Sun Solaris use this instead ### !/bin/env python # # check TCP settings for various Unix OSes # # Brian Tierney: bltierney@es.net # import commands, sys # set this to your recommended size recommended_size = 4 * 1024 * 1024 if __name__ == '__main__': uname = commands.getstatusoutput("uname")[1] if uname == 'Darwin' or uname == 'FreeBSD' or uname == 'BSD/OS': r = commands.getstatusoutput("sysctl kern.ipc.maxsockbuf")[1] bs = int(r.split()[1]) print "Your maximum TCP buffer size is set to: %d" % bs if bs < recommended_size: print "WARNING: %d is less than the suggested size of %d" % (bs, recommended_size) print "To set the maximum buffer size, add this to the file /etc/sysctl.conf" print " kern.ipc.maxsockbuf=%d" % recommended_size print "and then run:" print " sysctl -w kern.ipc.maxsockbuf=%d" % recommended_size else: print "TCP tuning looks good" elif uname == 'Linux': r = commands.getstatusoutput("sysctl net.ipv4.tcp_rmem")[1] bs = int(r.split()[4]) print "Your maximum TCP buffer size is set to: %d" % bs if bs < recommended_size: print "WARNING: %d is less than the suggested size of %d" % (bs, recommended_size) print "To set the maximum buffer size, add this to the file /etc/sysctl.conf" print " net.core.rmem_max=%d" % recommended_size print " net.core.wmem_max=%d" % recommended_size print " net.ipv4.tcp_rmem=4096 87380 %d" % recommended_size print " net.ipv4.tcp_wmem=4096 65536 %d" % recommended_size print "and then run:" print " sysctl -w net.core.rmem_max=%d" % recommended_size print " sysctl -w net.core.wmem_max=%d" % recommended_size print " sysctl -w net.ipv4.tcp_rmem='4096 87380 %d'" % recommended_size print " sysctl -w net.ipv4.tcp_wmem='4096 65536 %d'" % recommended_size else: print "TCP tuning looks good" # make sure tcp_moderate_rcvbuf is set too r = commands.getstatusoutput("sysctl net.ipv4.tcp_moderate_rcvbuf")[1] f = int(r.split()[2]) if f == 0: print "WARNING: tcp_moderate_rcvbuf is not set " print "To set tcp_moderate_rcvbuf, add this to the file /etc/sysctl.conf" print " net.core.tcp_moderate_rcvbuf=1" print "and then run:" print " sysctl -w net.core.tcp_moderate_rcvbuf=1" elif uname == 'SunOS': bs = commands.getstatusoutput("ndd /dev/tcp tcp_cwnd_max")[1] bs = int(bs) print "Your maximum TCP buffer size is set to: %d" % bs if bs < recommended_size: print "WARNING: %d is less than the suggested size of %d" % (bs, recommended_size) print "To set the maximum buffer size, run these commands: " print " ndd -set /dev/tcp tcp_cwnd_max %d" % recommended_size print " ndd -set /dev/tcp tcp_max_buf %d" % recommended_size else: print "TCP tuning looks good" else: print "Unknown system type" sys.exit()