Linux – Use puppet to make changes to ip route and sysctl

centoslinuxpuppet

I have two changes to ip route & sysctl that disable tcp slow start.
Here’s how I do it

ip route show

Make a note of the line starting with default.

Pick up the IP from the default line and run

sudo ip route change default via $ip_address dev eth0 initcwnd 12 
sudo sysctl -w net.ipv4.tcp_slow_start_after_idle=0

How can I create a puppet script out of this? One that can be deployed to many machines of the same type – CentOS 6

Edit:
Added bounty to get a working example for

sudo ip route change default via $ip_address dev eth0 initcwnd 12 

Best Answer

Going off of larsks answer, if you have static ip addresses, place this in /sbin/ifup-local

#!/bin/sh

GATEWAY=`ip route| awk '/^def/{print $3}'`
DEFGWDEV=`ip route| awk '/^def/{print $5}'`

if [ "$1" = $DEFGWDEV ]; then
  ip route change default via $GATEWAY dev $DEFGWDEV initcwnd 12
fi