It turns out that iptables doesn\'t handle leading zeros too well. As $machinenumber
that is used has to have a leading zero in it for other purposes, the idea
I also can't comment or vote up yet, but the Duncan Irvine answer is the best.
I'd like to add a note about portability. The $((10#0009))
syntax is not portable. It works in bash and ksh, but not in dash:
$ echo $((10#09))
dash: 1: arithmetic expression: expecting EOF: "10#09"
$ dpkg -s dash | grep -i version
Version: 0.5.7-2ubuntu2
If portability is important to you, use the sed answer.
If you don't have sed or awk or perl then you could use cut and grep
mn="$machinenumber"
while echo "$mn"|grep -q '^0';do mn=$(echo "$mn"|cut -c2-);done
iptables -t nat -I POSTROUTING -s 10.($machinetype).($mn).0/24 -j MASQUERADE
Works with both bash and dash shells.