Ubuntu Linux 14.04設定USB modem自動連線(以華為E3272作例子)

Submitted by saladlam on
目標:
  1. 在interface up時,get IP by DHCP前令到modem連線
  2. 在interface down時,release IP後令到modem斷線
工具:
  • comgt: 以指令行方式傳送一堆指令到modem的serial port,以操作modem。例如設定APN、連線、斷線等動作
假設modem的interface名稱為wwan0,Control serial port為"/dev/ttyUSB1",連線的APN為internet。
檔案"/etc/network/if-pre-up.d/wwan0-pre-up":
#!/bin/sh

if [ "$IFACE" = wwan0 ]; then
  /sbin/ifconfig wwan0 -arp
  /usr/bin/comgt -d /dev/ttyUSB1 -s /root/script/comgt-wwan0/up
fi

exit 0
檔案"/etc/network/if-post-down.d/wwan0-post-down":
#!/bin/sh

if [ "$IFACE" = wwan0 ]; then
  /usr/bin/comgt -d /dev/ttyUSB1 -s /root/script/comgt-wwan0/down
fi

exit 0
檔案"/root/script/comgt-wwan0/up":
opengt
set com 9600n81
set senddelay 0.05
waitquiet 2 0.5

send "AT\^"
send "NDISDUP=1,1,\"internet\""
send "^m"

exit 0
檔案"/root/script/comgt-wwan0/down":
opengt
set com 9600n81
set senddelay 0.05
waitquiet 2 0.5

send "AT\^"
send "NDISDUP=1,0"
send "^m"

exit 0

Add new comment

The content of this field is kept private and will not be shown publicly.

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
Enter the characters shown in the image.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.