Friday, January 17, 2020

How can I check DNS server on Ubuntu? (systemd based)

玩過SysV的朋友們,古早時期應該都會去看/etc/resolv.conf來查看目前機器所使用的DNS Server,不過這招在systemd架構下已經不管用了,取而代之的是透過以下的command來確定自己目前所使用的DNS server是哪一個IP。

$ sudo systemd-resolve --status | grep 'DNS Servers'

在此簡單紀錄一下。

Friday, November 22, 2019

Install Powerline in Ubuntu 18.04

Powerline是隻用Python寫的小外掛程式,主要是可以讓你的Linux shell變得更漂亮,而且安裝與配置上實在是非常簡單,只要以下兩個步驟就搞定囉!

Step1:
$ sudo apt-get install powerline

Step2:
$ vi ~/.bashrc
# Powerline
POWERLINE_SCRIPT=/usr/share/powerline/bindings/bash/powerline.sh
if [ -f $POWERLINE_SCRIPT ]; then
  source $POWERLINE_SCRIPT
fi

最後重新開啟一個新的shell或是登出/登入系統後,你就有一個漂亮的shell環境了!

使用前:

使用後:



11/28 更新:
總覺得初始值的Powerline+PS1實在太陽春了,網路上搜尋了一下,果然有強者做了加強版本來外掛!請參考Pureline讓你的tty更好用吧!

Friday, November 15, 2019

Install Notepad++ on Ubuntu

You can find Notepad++ from Sanp, so that you can install it with command below:

$ sudo snap install notepad-plus-plus






Wednesday, November 06, 2019

Ubuntu Server + desktop environment

雖然說Ubuntu Server預設只有文字介面可以使用,但使用者還是可以安裝上圖形介面環境(而且還很容易),只要執行以下3個命令,你就可以選擇自己所喜歡的桌面環境。

$ sudo apt-get install xubuntu-desktop
$ sudo apt-get install lubuntu-desktop
$ sudo apt-get install kubuntu-desktop

xubuntu, lubuntu, kubuntu的差別可以參考以下的連結。
Ubuntu各版本主要差異

如果想讓系統開機還是使用文字介面(runlevel 3)的話,可以執行以下的命令:
$ sudo systemctl set-default multi-user

反之執行以下的命令後系統又會切回圖形介面環境(runlevel 5):
$ sudo systemctl set-default graphical



Wednesday, October 09, 2019

計算Linux系統開機時間

現在大部分的Linux distro.應該都採用systemd,所以可以利用它內建的一隻command去幫我們計算出系統開機的時間,比如:
$ systemd-analyze
Startup finished in 31.365s (firmware) + 5.287s (loader) + 16.686s (kernel) + 55.716s (userspace) = 1min 49.056s
graphical.target reached after 55.345s in userspace

這邊可以看到系統開機到讓user可以登入前BIOS, boot loader, kernel與userspace分別花了多少時間。從上面的例子可以觀察到系統總共開機時間是大約1分49秒,BIOS花了31.365s,boot loader花了5.287s,kernel花了16.686s,userspace(所有services起來所需時間)是55.716s

如果要看是哪隻daemon佔用多少時間可以加上blame參數:
$ systemd-analyze blame

下次如果有人問你這個系統開機要花多久? 你就可以鬆了一口氣了。



Friday, July 26, 2019

How NB-IoT module (SIM7000-C) work on Rasberry Pi and Ubuntu Server 18.04

最近study了一下NB-IoT,並且稍微筆記了一下如何實作。

不過可惜的是我手邊目前並沒有NB-IoT的Sim卡,所以使用normal SIM卡搭配SIM7000C這張module做了些練習。

以下是我的測試設備:



  • Rasberry Pi 2B
  • Waveshare SIM7000C NB-IoT HAT
  • CHT(中華電信) normal SIM
  • OS: Ubuntu Server 18.04

How to connect with CHT cell site via AT commands:

Connect to SIM7000C via USB-console:

$ sudo screen /dev/ttyUSB3 115200

Examine SIM7000C is ready to use

at

Check PIN status

at+cpin?
Ready: SIM is not pending for any password.

Configure APN(Access Point Name) automatically

at+cgdcont=1,”ip”,””
1: cid
ip: packet data protocol type 
“”: apn

Check signal

at+csq
+csq: rssi, ber
rssi:
0 -115 dBm or less
1 -111 dBm
2...30 -110... -54 dBm
31 -52 dBm or greater
99 not known or not detectable
ber:0...7 As RXQUAL values in the table in GSM 05.08 [20] subclause 7.2.4

Scan cell site:

It will take about 120 secs or more, and 46692 is CHT.
at+cops=?
+cops=?
(index,format,oper)
Index: Integer type: order number of operator in SIM preferred
Format: 3GPP MCC/MNC
MCC
MNC
ISP
466
11
中華電信 (CHT)
466
92
中華電信 (CHT)
466
93
台灣大哥大
466
97
台灣大哥大
466
99
台灣電信
466
03
遠傳電信
466
01
遠傳電信
466
88
遠傳電信
466
89
台灣之星
466
12
亞太電信
466
12
亞太電信
oper: String type(string should be included in quotation marks)

Number
Type
0
GSM
7
CAT-M1
9
NB-IoT

Connect to CHT cell site:

at+cops=1,2,”46692”

at+cgatt?

at+cpsi?
+cops=index,format,oper

Get APN

We need APN for connecting to the Internet.
It seems normal CHT SIM card is used internet as APN, and NB-IoT of CHT is internet.iot.
at+cgnapn
+cgnapn valid,APN
0: The network did not sent APN parameter to UE.In the case, is NULL.
1: The network sent APN parameter to UE.

Connect to the Internet

at+cstt=”internet”
+cstt APN,username,password

Initial mobile data network

at+ciicr

Check public IP address

at+cifsr

Test1: Ping testing 

at+cipping=”168.95.1.1”

Test2: TCP testing

at+cipstart=”tcp”,”ftp.isu.edu.tw”,21
+cipstart=mode,ip,port
Mode: tcp,udp

看到這裡相信很多人已經放棄了,不過請別氣餒其實有更簡單好用的方法唷!


Connect to the Internet via nmcli and mmcli

Issue: nmcli cannot manage interfaces


# nmcli c up id GSM

Error: Connection activation failed: No suitable device found for this connection.

Workaround:


# mv /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf  /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf_orig

# touch /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf

# systemctl restart network-manager

Ensure that mmcli can recognize and scan cell site


# mmcli -m 0

 --------------------------------
  General  |     dbus path: /org/freedesktop/ModemManager1/Modem/0
           |            device id: fa2d54b8e3ad72c95e99f28ba51b4ce48565684b
  --------------------------------
  Hardware |         manufacturer: QUALCOMM INCORPORATED
           |                model: 0
           |             revision: MPSS.JO.3.0.2.c3-00140-9607_LTEONLY_PACK-1  1 [Feb 01 2018 07:00:00]
           |         h/w revision: 10000
           |            supported: gsm-umts, lte
           |              current: gsm-umts, lte
           |         equipment id: 865233030789763
  --------------------------------
  System   |       device: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3
           |              drivers: option1, qmi_wwan
           |               plugin: SimTech
           |         primary port: cdc-wdm0
           |                ports: ttyUSB0 (qcdm), ttyUSB2 (at), cdc-wdm0 (qmi), wwan0 (net), 
           |                       ttyUSB3 (at)
  --------------------------------
  Status   |         lock: sim-pin2
           |       unlock retries: sim-pin (3), sim-pin2 (3), sim-puk (10), sim-puk2 (10)
           |                state: registered
           |          power state: on
           |          access tech: lte
           |       signal quality: 94% (recent)
  --------------------------------
  Modes    |     supported: allowed: 2g; preferred: none
           |                       allowed: 4g; preferred: none
           |                       allowed: 2g, 4g; preferred: 4g
           |                       allowed: 2g, 4g; preferred: 2g
           |              current: allowed: 2g, 4g; preferred: 4g
  --------------------------------
  Bands    |     supported: egsm, dcs, pcs, g850, eutran-1, eutran-3, eutran-5, eutran-8
           |              current: egsm, dcs, pcs, g850, eutran-1, eutran-3, eutran-5, eutran-8
  --------------------------------
  IP       |     supported: ipv4, ipv6, ipv4v6
  --------------------------------
  3GPP     |         imei: 865233030789763
           |          operator id: 46692
           |        operator name: 466 92
           |         registration: home
  --------------------------------
  3GPP EPS | ue mode of operation: csps-2
  --------------------------------
  SIM      |     dbus path: /org/freedesktop/ModemManager1/SIM/0



# mmcli -m 0 --3gpp-scan --timeout=120

  ---------------------
  3GPP scan | networks: 46612 - 466 12 (lte, available)
            |           46692 - 466 92 (lte, current)
            |           46605 - 466 05 (gsm, forbidden)

Connect to the Internet with nmcli


# nmcli c add type gsm ifname "*" con-name GSM apn "internet"

Connection 'GSM' (e79462c8-d02d-4ae0-b3f4-a08db28087af) successfully added.

# nmcli c up id GSM

相信這個方法簡單了許多吧!不過了解一下底層的AT command如何運作也是相當不錯的機會啦!以下是AT command完整的說明文件: http://www.waveshare.net/w/upload/4/49/SIM7000_Series_AT_Command_Manual_V1.02.pdf

Appendix:

AT+CMNB Preferred selection between CAT-M and NB-IoT.

+cmnb: mode
1 LTE CAT-M
2 NB-IoT
3 CAT-M and NB-IoT

SIM7000C + pppd撥接上網

  1. To remove modemmanager firstly, otherwise ppp0 connection will be terminated by it.
$ sudo apt remove modemmanager

  1. To install ppp
$ sudo apt install ppp

  1. Configured ppp script for adding some AT commands.
$ cd /etc/ppp
$ vi gprs-connect-chat

TIMEOUT 15
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
TIMEOUT 40
'' \rat
OK at+cstt=\"internet\"
OK at+cgatt?
OK at+cpsi?
OK at+ciicr
OK ATD*99***1#
CONNECT

  1.  Configured ppp dial-in configuration file:
$ cd /etc/ppp/peers
$ vi gprsdial

/dev/ttyUSB3
115200
crtscts
modem
debug
nodetach
usepeerdns
noipdefault
defaultroute
0.0.0.0:0.0.0.0
connect '/usr/sbin/chat -s -v -f /etc/ppp/gprs-connect-chat'

  1. Added “noauth” parameter in /etc/ppp/options
  2. Plug-in SIM7000C.
  3. To execute pppd call 
$ sudo pppd call gprsdial

root@Lawrence-ThinkPad-T420S:/etc/ppp/peers# pppd call gprsdial 
timeout set to 15 seconds
abort on (DELAYED)
abort on (BUSY)
abort on (ERROR)
abort on (NO DIALTONE)
abort on (NO CARRIER)
timeout set to 40 seconds
send (^Mat^M)
expect (OK)
^M
DST: 0^M
^M
*PSUTTZ: 19/06/26,08:14:58","+32",0^M
at^M^M
OK
 -- got it

send (at+cstt=\"internet\"^M)
expect (OK)
^M
at+cstt="internet"^M^M
OK
 -- got it

send (at+cgatt?^M)
expect (OK)
^M
at+cgatt?^M^M
+CGATT: 1^M
^M
OK
 -- got it

send (at+cpsi?^M)
expect (OK)
^M
at+cpsi?^M^M
+CPSI: LTE NB-IOT,Online,466-92,0xC8C9,54027119,280,EUTRAN-BAND8,3640,0,0,-9,-59
,-50,20^M
^M
OK
 -- got it

send (at+ciicr^M)
expect (OK)
^M
at+ciicr^M^M
OK
 -- got it

send (ATD*99***1#^M)
expect (CONNECT)
^M
ATD*99***1#^M^M
CONNECT
 -- got it

Script /usr/sbin/chat -s -v -f /etc/ppp/gprs-connect-chat finished (pid 2813), status = 0x0
Serial connection established.
using channel 12
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB3
sent [LCP ConfReq id=0x1 ]
rcvd [LCP ConfReq id=0x0 ]
sent [LCP ConfNak id=0x0 ]
rcvd [LCP ConfAck id=0x1 ]
rcvd [LCP ConfReq id=0x1 ]
sent [LCP ConfAck id=0x1 ]
sent [LCP EchoReq id=0x0 magic=0x640f0536]
sent [PAP AuthReq id=0x1 user="Lawrence-ThinkPad-T420S" password=]
rcvd [LCP DiscReq id=0x2 magic=0xd41b8a15]
rcvd [LCP EchoRep id=0x0 magic=0xd41b8a15 64 0f 05 36]
rcvd [PAP AuthAck id=0x1 ""]
PAP authentication succeeded
sent [CCP ConfReq id=0x1 ]
sent [IPCP ConfReq id=0x1 ]
rcvd [LCP ProtRej id=0x3 80 fd 01 01 00 0f 1a 04 78 00 18 04 78 00 15 03 2f]
Protocol-Reject for 'Compression Control Protocol' (0x80fd) received
rcvd [IPCP ConfReq id=0x0]
sent [IPCP ConfNak id=0x0 ]
rcvd [IPCP ConfRej id=0x1 ]
sent [IPCP ConfReq id=0x2 ]
rcvd [IPCP ConfReq id=0x1]
sent [IPCP ConfAck id=0x1]
rcvd [IPCP ConfNak id=0x2 ]
sent [IPCP ConfReq id=0x3 ]
rcvd [IPCP ConfAck id=0x3 ]
Could not determine remote IP address: defaulting to 10.64.64.64
not replacing default route to enp0s25 [10.101.47.1]
local  IP address 10.169.25.71
remote IP address 10.64.64.64
primary   DNS address 168.95.1.1
secondary DNS address 168.95.192.1
Script /etc/ppp/ip-up started (pid 2824)
Script /etc/ppp/ip-up finished (pid 2824), status = 0x0

$ ifconfig ppp0
ppp0: flags=4305  mtu 1500
        inet 10.169.25.71  netmask 255.255.255.255  destination 10.64.64.64
        ppp  txqueuelen 3  (Point-to-Point Protocol)
        RX packets 9  bytes 382 (382.0 B)
        RX errors 0  dropped 0 overruns 0  frame 0
        TX packets 18  bytes 1385 (1.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0 collisions 0

$ ping 168.95.1.1 -I ppp0 -c 3
PING 168.95.1.1 (168.95.1.1) from 10.169.121.115 ppp0: 56(84) bytes of data.
64 bytes from 168.95.1.1: icmp_seq=1 ttl=248 time=292 ms
64 bytes from 168.95.1.1: icmp_seq=2 ttl=248 time=460 ms
64 bytes from 168.95.1.1: icmp_seq=3 ttl=248 time=267 ms

--- 168.95.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 267.265/340.248/460.987/85.994 ms