Rexxer

Some tips for me and other

PFSense + DHCP issues from provider

I met a strange issue with an internet channel from my provider: it doesn’t assign an IP (PFSense gets 0.0.0.0 and the provider blocks me) via DHCP or the channel stops working(IP is assigned).

I suppose provider has got several DHCP-servers and they are configured with to much security.

So, I wrote a script to detect these issues, change a mac and reset dhcp-client:

#!/bin/sh

# Prepare a mail
echo “To: admin@contoso.com” > /usr/local/etc/mail2.txt
echo “From: admin@mydomain.com” >> /usr/local/etc/mail2.txt
echo “Subject: DHCP RESET” >> /usr/local/etc/mail2.txt
echo “text” >> /usr/local/etc/mail2.txt

# Check ping
ping -c 2 -S 8.8.8.50 8.8.8.1 >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo ” Ping [OK]”
ISP1_stat=”0″
echo “Ping OK, checking the DHCP …” >> /usr/local/etc/mail2.txt
else
echo ” Ping [FAILED]”
ISP1_stat=”1″
echo “Ping failed” >> /usr/local/etc/mail2.txt
fi

# Get IP-address for rl0
mac=`ifconfig rl0 | grep ether | awk ‘{print $2}’`
ip=`ifconfig rl0 | grep “inet ” | awk ‘{print $2}’`
echo $ip $mac
if [ “$ip” == “” ] || [ “$ip” == “0.0.0.0” ] || [ “$ISP1_stat” == “1” ]; then
echo “No IP assigned for rl0 … /n Resetting MAC … /n”
ifconfig rl0 down
if [ “$mac” -eq “c8:d3:a3:83:c9:a2” ]; then
ifconfig rl0 ether c8:d3:a3:83:c9:a3
fi
if [ “$mac” -eq “c8:d3:a3:83:c9:a3” ]; then
ifconfig rl0 ether c8:d3:a3:83:c9:a2
fi
ifconfig rl0 up
killall dhclient
dhclient rl0
/usr/local/sbin/ssmtp admin@contoso.com < /usr/local/etc/mail2.txt
fi
echo $ISP1_STAT
echo “rl0 ip: $ip – everything is ok.”

Comments are currently closed.