IPTABLES cPanel script set outgoing IP as dedicated

iptables -t nat -A POSTROUTING -o eth0 -m owner --uid-owner *USERNAME* -j SNAT --to 198.51.100.10

Do I need to comment that? 😉

 

Oh, wait. Maybe some script to do it easier?

#!/bin/bash
for file in /var/cpanel/users/*; do
        fname=$(basename $file)
        ip=$(grep "IP=" $file | cut -d "=" -f 2)
        hip=$(hostname -i)

        if [ "$ip" != "$hip" ]
        then
                echo iptables -t nat -A POSTROUTING -o eth0 -m owner --uid-owner $fname -j SNAT --to $ip
        fi
done