Syed Jahanzaib – Personal Blog to Share Knowledge !

May 28, 2014

PTCL vDSL modem hang issue and its workaround

Filed under: Mikrotik Related — Tags: , , , — Syed Jahanzaib / Pinochio~:) @ 2:35 PM

modem

Updated: October, 2014

The script is well tested with mikrotik 5.2x only

Recently at a network, the operator was facing PTCL 50mb via vDSL modem (HUAWEI HG622 & CELLPIPE model) hangs frequently. The interval between hanging was different , sometimes 3-4 times daily or after 14-16 hours. Ping to the modem also timeout and when the operator restart the modem, every thing works fine, but its painful to do it manually specially in late night hours when no one at help desk to do the stupid job of resetting.

[It is also observed that PTA is actively blocking users public ips from which suspected grey traffic (Like VPN, HOTSPOT SHIELD and tunneling type applications, and specially VOIP) is passing through, so disconnecting , and reconnecting again assigns you new public ip and internet starts working again.)

The workaround I made was to

  • Try Using Good Quality UPS with automatic voltage control,
  • Configured the modem in BRIDGE mode,
  • Add pppoe client dialer in the Mikrotik ppp section,so mikrotik handles the wan dialing itself, not the modem
  • Then add a script with scheduler which will keep checking two internet hosts connectivity at 1 minute interval or as required) , and if it found no reply from both host , then it disables the default dialer (pppoe-out1) and redial the connection after 10 seconds of PAUSE/DELAY (to prevent any dial-flood).
  • It also sends an email to admin [configurable] so that he should be aware of what happening behind his back 😛 . You can skip email section if you don’t require notifications.

SCRIPT FOR MULTIPLE HOST MONITORING

 

Following is an EXPORT version of the script, name it wanmonitor. You should modify it as per your local need.

# Following script is a modified version from the Mikrotik forum.
# http://forum.mikrotik.com/viewtopic.php?f=9&t=85505
# Modified few contents to suite local requirements and description added
# Regard's / Syed Jahanzaib / https://aacable.wordpress.com

# Script Starts here...
# DUAL Internet Host (to avoid false failure) to be checked You can modify them as per required, JZ

# set GMAIL smtp IP auto
:global gmailsmtp
:set gmailsmtp [:resolve "smtp.gmail.com"];

# Add two hosts for monitoring internet connectivity
:local host1   "8.8.8.8"
:local host2   "208.67.222.123"
 
# Do not modify data below without proper understanding.
:local i 0;
:local F 0;
:local date;
:local time;
:global InternetStatus;
:global InternetLastChange;
 
# PING each host 5 times
:for i from=1 to=5 do={
if ([/ping $host1 count=1]=0) do={:set F ($F + 1)}
if ([/ping $host2 count=1]=0) do={:set F ($F + 1)}
:delay 1;
};
 
# If both links are down and all replies are timeout, then link is considered down
:if (($F=10)) do={
:if (($InternetStatus="UP")) do={
:log error "WARNING : The INTERNET link seems to be DOWN. Please Check";
:set InternetStatus "DOWN";
 
## ADD YOUR RULES HERE, LIKE ROUTE CHANGE OR WHAT EVER IS REQUIRED, Example is below ...
:log error "PTCL LINK SEEMS TO BE DOWN, Resetting PPPoE Dialer and wait for at least 10 seconds before redialing / zaib"
 /interface pppoe-client disable pppoe-out1
/sys script run siren
:delay 10
 /interface pppoe-client enable pppoe-out1

:set date [/system clock get date];
:set time [/system clock get time];
:set InternetLastChange ($time . " " . $date);
} else={:set InternetStatus "DOWN";}
} else={
 
## If reply is received , then consider the Link is UP
:if (($InternetStatus="DOWN")) do={
:log warning "WARNING :The INTERNET link have been restored";
:set InternetStatus "UP";
 
## ADD YOUR RULES HERE, LIKE ROUTE CHANGE OR WHAT EVER IS REQUIRED, Example is below ...
:local currentIP
:local externalInterface "pppoe-out1"

## get the current IP address from the external interface
:set currentIP [/ip address get [find interface="$externalInterface"] address]

## Strip netmask
:for i from=( [:len $currentIP] - 1) to=0 step=-1 do={
:if ( [:pick $currentIP $i] = "/") do={
:set currentIP [:pick $currentIP 0 $i]

# Show warning in Mikrotik LOG window
:log warning "PTCL LINK RE - CONNECTED with new WAN IP = $currentIP, Please check and confirm / zaib"

# Disable or Enable EMAIL alert feature as required
#/tool e-mail send to="aacable@hotmail.com.com" password=YOURMAILPASSWD subject="$[/system clock get date] $[/system clock get time] -- PTCL DSL pppoe Dialer RE-CONNECTED AND UP NOW, New WAN IP is $currentIP / zaib" from=aacable79@gmail.com server=$gmailsmtp tls=yes body="$[/system clock get date] $[/system clock get time] : PTCL Link was down, so the wan monitor script disconnected the pppoe-out1 dialer and reconnected after 10 seconds of delay. New WAN IP is $currentIP  . Thank you / aacable@hotmail.com"

}
}
 
:set date [/system clock get date];
:set time [/system clock get time];
:set InternetLastChange ($time . " " . $date);
} else={:set InternetStatus "UP";}
}
 
# Script Ends Here.
# Thank you / zaib

.

SCHEDULER CONFIGURATION (to check wan connectivity every minute)


/system scheduler
add comment="Schedular for WAN Monitor tun run every minute on MT" disabled=no interval=1m name="wan monitor script 1 minute check" on-event=wanmonitor policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-date=jul/10/2014 start-time=16:34:32

 

EMAIL CONFIGURATION (if email alerts are required)

You can skip this email config section if you don’t want to receive notifications via email. also you have to remove it from the main script also. Modify the gmail smtp as required.


/tool e-mail
set address=173.194.69.109 from=your_email@gmail.com password=your_password port=587 starttls=no user=your_username

Done.


 

 

When there will be no response from the internet (Google dns or hosts you have set) , then netwatch will trigger down script section, which will disconnect the active pppoe-out1 dialer connection, wait 10 seconds, then redial the connection again and log alert and shoots email.

As showed in the image below …

1- link up


 

 

1.

.

.


 

NOTES

  • You can increase the interval and timeout value as per your requirement, ideally it should be a bit higher.
  • Its recommended to monitor your ISP gateway + one internet host to avoid False result.

Second Version of the above script with sms / email support, and re connect wan pppoe-out1 dialer


# WAN 1 Monitor Script for mikrotik by using two internet host
# With optional Email and SMS Alert, modem is attached to local mikrotik in this example
# but i have added kannel sms gateway and gmail option too. Added many variables
# by Syed Jahanzaib
# https://aacable.wordpress.com
# Email : aacable at hotmail dot com
# Script Last Modified : 25-NOV-2015 / 13:00

# Set variables
:local i 0;
:local F 0;
:local date;
:local time;
:global "DSL1netstatus"
:global "dsl1netlastchange"

# Check dsl-1 GATEWAY to be monitored (Currently we are monitoring internet host AROOT DNS)
:global dsl1host1 "4.2.2.1"
:global dsl1host2 "199.7.83.42"

#:global dsl1host1 "4.2.2.8"
#:global dsl1host2 "199.7.83.8"


# Number of Ping Count, how many times each host should ping
:local PINGCOUNT "30"

# PING HTRESHOLD, Multiply above value with 2 , so if you have select 5 in above example, then set below $PINGTS to 10
:local PINGTS "60"

# Setting SMS Number for admin
:local cell1 "03333021909"
# Company Name
:local COMPANY "ZAIB"

#If you dont have kannel sms gateway ignore this.
:local KURL "http://KANNEL_IP:13013/cgi-bin/sendsms"
:local KID "kannel"
:local KPASS "kpass"

# SMS Msg format for localy attached modem in mikrotik
:local MSGDOWN "$COMPANY WAN ALERT: DSL-1 is DOWN."
:local MSGUP "$COMPANY WAN INFO: DSL-1 is UP"

# Set USB Port on which usb modme is connected in Mikrotik
:local PORT "usb3"

# SMS Msg format for Kannel SMS gateway
#:local MSGDOWN "$COMPANY+WAN+ALERT:+DSL-1+is+DOWN."
#:local MSGUP "$COMPANY+WAN+INFO:+DSL-1+is+UP"


# Gmail SMTP Address / If you dont want to send email disable these
:global "gmailsmtp"
:set gmailsmtp [:resolve "smtp.gmail.com"];
:local GMAILID "YOURGMAILID@gmail.com"
:local GMAILPASS "GMAILPASS"

# Alerts n info m Send to following Support addressess
:local TO1 "ADMINMAIL@hotmail.com"
:local TO2 "ADMINMAIL2@gmail.com"

# Email Subject for DOWN Alert
:local SUBDOWN "$[/system clock get date] $[/system clock get time] -- $COMPANY_ALERT: dsl-1 Primary Internet Link DOWN"
# Email Body for DOWN Alert
:local BODYDOWN "-- dsl-1 Primary Internet Link  at $COMPANY DATA CENTER not responding, \n\nPlease check conectivity... \n\n>>>  Script Designed by ***   Syed_Jahanzaib   ****  <<<"

# Email Subject for UP Alert
:local SUBUP "$[/system clock get date] $[/system clock get time] -- $COMPANY_INFO: dsl-1 Primary Internet Link is now UP"
# Email Body for UP Alert
:local BODYUP "-- dsl-1 Primary Internet Link  at $COMPANY DATA CENTER have been restored \n\n>>>  Script Designed by ***   Syed_Jahanzaib   ****  <<<"



#######################################
#######################################
########## Start the SCRIPT ###########
########## DONOT EDIT BELOW ###########
#######################################
#######################################

# PING each host $PINGCOUNT times
# IF NOT A SINGLE PING SUCCESSFULL THEN CONSIDER LINK DOWN ## ZAIB
:for i from=1 to=$PINGCOUNT do={
if ([/ping $dsl1host1 count=1]=0) do={:set F ($F + 1)}
if ([/ping $dsl1host2 count=1]=0) do={:set F ($F + 1)}
:delay 1;
};


# If no response (all ping counts fails for both hosts, Time out, then LOG down status and take action
:if (($F=$PINGTS)) do={
:if (($DSL1netstatus="UP")) do={
:set DSL1netstatus "DOWN";

# Also add status in global variables to be used as tracking
:set date [/system clock get date];
:set time [/system clock get time];
:set dsl1netlastchange ($time . " " . $date);


##################################################
####### FOR DOWN STATUS, CHANGE THE RULES ########
##################################################

# If the link is down, then LOG info and warning in Mikrotik LOG window [Zaib]
:log error "DSL1  Gateway Not Responding..."
:log error "DSL1  Gateway Not Responding..."
:log error "DSL1  Gateway Not Responding..."

# "Emailing the DOWN status. . . "
/tool e-mail send to="$TO1" subject="$SUBDOWN" body="$[/system clock get date] $[/system clock get time]:$BODYDOWN" from=$GMAILID password=$GMAILPASS  server=$gmailsmtp start-tls=yes
/tool e-mail send to="$TO2" subject="$SUBDOWN" body="$[/system clock get date] $[/system clock get time]:$BODYDOWN" from=$GMAILID password=$GMAILPASS  server=$gmailsmtp start-tls=yes

# Send SMS via KANNEL
#/tool fetch url="$KURL\?username=$KID&password=$KPASSto=$cell1&text=$MSGDOWN"

# Send SMS via Mikrotik attached modem
/tool sms send port=$PORT phone-number=$cell1 message="$MSGDOWN" channel=0

# Disable pppoe-out1 wan1 dialer and try to re-connect one time only
:log error "DISABLING PPPOE-OUT1 WAN DIALER"
/interface pppoe-client disable pppoe-out1
:delay 10
:log warning "EN-ABLING PPPOE-OUT1 WAN DIALER"
/interface pppoe-client enable pppoe-out1

##################################################
####### FOR UP STATUS, CHANGE THE RULES ########
##################################################
# If ping is ok for 1 host as well reply received, then LOG UP and take action as required
} else={:set DSL1netstatus "DOWN";}
} else={
:if (($DSL1netstatus="DOWN")) do={

:set DSL1netstatus "UP";
# If link is UP, then LOG info and warning in Mikrotik LOG window [Zaib]
log warning "DSL1  Gateway RESTORED ..."
log warning "DSL1  Gateway RESTORED ..."
log warning "DSL1  Gateway RESTORED ..."


# "Emailing the UP status. . . "
/tool e-mail send to="$TO1" subject="$SUBUP" body="$[/system clock get date] $[/system clock get time] $BODYUP" from=$GMAILID password=$GMAILPASS server=$gmailsmtp start-tls=yes
/tool e-mail send to="$TO2" subject="$SUBUP" body="$[/system clock get date] $[/system clock get time] $BODYUP" from=$GMAILID password=$GMAILPASS server=$gmailsmtp start-tls=yes

# Send SMS via KANNEL Gateway
#/tool fetch url="$KURL\?username=$KID&password=$KPASSto=$cell1&text=$MSGUP"

# Send SMS via Mikrotik attached modem
/tool sms send port=$PORT phone-number=$cell1 message="$MSGUP" channel=0

:set date [/system clock get date];
:set time [/system clock get time];
:set dsl1netlastchange ($time . " " . $date);

} else={:set DSL1netstatus "UP";}
}


 

Howto create WAN PPPOE DIALER in Mikrotik

1- mt pppoe

 

2- pppo 2

 

3- pppo 3

 

4-connectred

DONE.


 

Regard’s
Syed Jahanzaib

20 Comments »

  1. nice !

    Like

    Comment by FSK — May 28, 2014 @ 4:28 PM

  2. Dear Syed,

    I work in a large telecom company and we have internet services provided with Huawei routers and they work fine untill there are power fluctuations and the equipment is freezing. I recommend to use a UPS device with automatic voltage regulator.

    Regards,
    Adrian

    Like

    Comment by Adi — May 29, 2014 @ 11:25 AM

    • yes having a good quality UPS saves you from few nu-expected issues. at company I work for have Emerson 10k x2 online UPS in fail-over and load balance mode, and it works really awesome 🙂

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — May 29, 2014 @ 7:45 PM

      • how i can give users full speed to browsing and limit download

        Like

        Comment by ibrahiem — May 30, 2014 @ 9:31 PM

  3. for multiple wan cases,what should we do?

    Like

    Comment by irfan — June 16, 2014 @ 3:01 PM

  4. i am facing the problem that my dsl connection going down frequently and i find that my ip got block and i dont know which software or ports using my clients how can i find the ports or site then i will block it or you can tell me which ports pta is not allow on dsl i am very greatfull if you tell me sloution

    regards Amin

    Like

    Comment by amin — November 16, 2014 @ 9:54 PM

  5. I’m using PTCL VDSL 50mb and getting SMTP issue, its seems that every 2 hours SMTP service dtop drom PTCL DSL. did anyone notice… check it by typing this command at Command Prompt: telnet smtp-server.com 25

    Like

    Comment by Kashif Khan — November 18, 2014 @ 12:39 PM

  6. salam.. bhai ma ny 50 mb vdsl2 install krwaya ha but 23 mb aa rha ha. phr ma ny 30 mb krwaya ha phr b 23 mb he aa rha ha. ptcl walon ko b smajh nai aa rae.. aur 1 problem aur b ha… dsl light kbi kbi aur internet light din main 5,7 dafa bilkhasus rat ko kafi red rehti ha… phr khud thk ho jati ha ya restart krny sy thk ho jati ha.kya problem ha ye.. tang aa gya hu main.. plz help

    Like

    Comment by farooq — August 20, 2015 @ 1:44 AM

  7. can it be helped by changing vdsl router from cell pipe to tplink wd-9977 ?
    or last solution is only #Mikrotik RB ?

    Like

    Comment by Talha Sheikh — October 14, 2015 @ 11:56 PM

    • obviously changing modem will solve the hang issue.
      but still connecting pppoe dialer directly via mikrotik/router is recommended dueto various performance and management reasons.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — October 16, 2015 @ 11:22 AM

  8. Hello friend I got a vdsl 20 my connection 2 months ago I am facing almost the same problem my cell pipe 7130 provided by Ptcl. What my router does is that it hangs all my lan connections at times in 2 hours some less or may be sometimes more then that. But the strange thing is that my cell pipe wifi is providing me with the Internet perfectly so it’s just the lan connections that get hanged then I have to reboot the cell pipe and it starts working fine. For now to work a way out I got a wifi to link extender and placed it next t the cell pipe and the extender has one port out through which I have connected my whole house which means all the lab connections. So far I haven’t faced any issues of hang as their is no lan connection directly going to the cell pipe else the extender is connected to the cell pipe and the extender is on wifi and all lan connections are connected to the extender the extender is 300 mpbs but still I don’t get speeds properly. If I connect directly to the vdsl I get 19.20 all the time peak or of but with the above method it varies sometimes it goes as low as 13 mpbs and sometimes it gives me max 19 I am sick of this please help me I have all
    Macs no windows

    Like

    Comment by Omer — January 22, 2016 @ 12:27 AM

  9. How can i fix this in Dlink DSL-225 router that also hangs once a day. H/W: J1

    Like

    Comment by ali — February 11, 2017 @ 9:54 PM

  10. Can Please Somebody tell me the complete method of bridge mode of VDSL Modem…. I Reset Modem Many time but bridge mode not established… Thanks!!! I am Waiting for your Valuable suggestions…

    Like

    Comment by Abaidullah — May 3, 2017 @ 11:41 PM

  11. assalam O alaikum Sir is ko use kaisay kare ge ?

    Like

    Comment by Arsalan — May 23, 2017 @ 6:52 PM

  12. Jahanzeb Sab, Can you please help me in the same senario of configuring the VDSL modem in Bridge Mode ? I am having Dlink 225 model, under WAN Service there are multiple profiles of ADSL as well as VDSL. The VDSL have 2 default profiles, one with Bridge having its own VLAN ID, and one with PPPoE having its own VLAN ID. I have removed all the profiles only left the bridge profile with its VLAN ID, but unable to dial-out the Username and password from Mikrotik or Laptop. Kindly post this in addition to your current post so not only me but everyone can get full advantage from your post.

    Like

    Comment by Qamar Sultan — November 17, 2017 @ 8:56 AM

    • personally i have not made any modem in bridge mode. kindly contact thestrangereyes @ hotmail . com / mr jahangir , he have good understanding of doing config of vdsl modems.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — November 20, 2017 @ 4:43 PM

      • Thanks for your prompt response.

        Like

        Comment by Qamar Sultan — November 25, 2017 @ 12:16 AM

  13. Jahanzeb bhai, i have tried to reach Mr. Jahangir several times through his only email address but did not receive any response from him till todate. Kindly have a work on VDSL configuration in bridge mode and post here so that everyone can configure the PTCL VDSL modem in bridge mode. They are issuing VLAN MUX ID in PPPOE and Bridge profiles. I had tried to configure Mikrotik Interface with the same VLAN ID but it is not working and unable to dial-out the username and password.
    If you can share the contact number of Mr. Jahangir i will try to reach him and hopefully he can help us to sort out the problem.

    Like

    Comment by Qamar Sultan — December 13, 2017 @ 4:32 PM

    • i have same issue I am also doing dsl-225 on bridge mode (1st time)

      Like

      Comment by Kashif — December 13, 2017 @ 11:13 PM


RSS feed for comments on this post. TrackBack URI

Leave a comment