顯示具有 Linux應用 標籤的文章。 顯示所有文章
顯示具有 Linux應用 標籤的文章。 顯示所有文章

2023年9月15日 星期五

Nmap 開源的網路掃描與檢測工具

Nmap 是開源的網路掃描與檢測工具, 以下是 nmap 的範例。

如果系統內沒有安裝 nmap, 可以用系統的套件管理工具安裝:

RHEL, CentOS, Fedora:

# yum install nmap

Debian, Ubuntu:

# apt-get install nmap

安裝 nmap 後, 便可以開始使用 nmap.


掃瞄 IP 地址或 Hostname:

Netcat 是 Linux 系統下常用的網路工具

Netcat 是 Linux 系統下管理者常用的網路工具,這裡蒐集一些關於 Netcat 實用的範例。

Netcat 是 Linux 系統中一個多功能的工具程式,雖然它只是一個小程式,但是能夠做的事情很多,就像瑞士刀一樣,幾乎任何使用 TCP 或 UDP 封包的動作都可以用它來達成,是許多系統管理者(包含我自己)最喜愛的網路診斷工具之一。

Netcat 這個工具在 Linux 系統中的指令名稱是 nc,以下是各種 nc 指令的實用範例。
在一般的 Linux 系統中,從 0 到 1023 這個範圍的連接埠(port)是需要有 root 權限才能使用的,而 1024 以上的連接埠則是可以讓一般的使用者使用,在使用 Netcat 時請注意這個權限問題。
========
Ncat 

安裝:
RHEL, CentOS, Fedora:
# yum install -y nc

測試特定的 TCP 連接埠(port)是否有開啟

nc 可以用來檢測伺服器特定的連接埠(port)是否有開啟:
nc -v 192.168.0.175 5000
若輸出為:
nc: connect to 192.168.233.208 5000 (tcp) failed: Connection refused
這樣就表示該連接埠沒有開啟。


## nc -vuz 192.168.209.121 123
連接192.168.209.121 123端口[udp/ntp]成功!

實際使用時可以只用-u參數,-u代表udp協議,-v代表詳細模式,-z代表只監測端口不發送數據。


2022年3月15日 星期二

DNS 問題除錯 dig 指令使用教學與範例

DNS 問題除錯 dig 指令使用教學與範例

介紹如何使用 dig 指令查詢各種 DNS 記錄,進行 DNS 審視與除錯。

安裝 dig

若要在 CentOS Linux 中安裝 dig 指令,可以使用 yum 安裝 bind-utils 套件:

# 安裝 bind-utils 套件(CentOS)
sudo yum install bind-utils

若在 Ubuntu Linux 中則可使用 apt 安裝 dnsutils 套件:

# 安裝 bind-utils 套件(Ubuntu)
sudo apt install dnsutils

基本 DNS 記錄查詢

執行 dig 並指定完整的主機名稱,即可進行 DNS 正向查詢,靠系統預設的 DNS 伺服器取得對應的 IP 位址:

# 查詢 DNS 記錄
dig www.google.com
; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38378
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;www.google.com.                        IN      A

;; ANSWER SECTION:
www.google.com.         298     IN      A       216.58.200.228

;; Query time: 9 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Sun Jul 19 19:32:18 CST 2020
;; MSG SIZE  rcvd: 59

dig 預設的輸出非常詳細,這裡的輸出大致上可分為四的部份,第一個區塊顯示了本次 DNS 查詢的技術細節,包含查詢參數與傳回值等。QUESTION SECTION 部份顯示了送出的 DNS 查詢內容,預設的查詢類型為 IPv4 位址(A 記錄)。ANSWER SECTION 部份顯示了本次 DNS 查詢的結果。最後一部分則是一些附加資訊,例如 DNS 伺服器位址等。

簡略輸出

若感覺 dig 的輸出過於冗長,可以加上 +short 參數改用簡略的輸出格式,這種輸出在撰寫指令稿時會比較好處理:

# 簡略輸出
dig www.google.com +short
216.58.200.228

另一種簡略的輸出方式是只輸出答案資訊部份:

# 只輸出答案資訊
dig www.google.com +noall +answer
; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> www.google.com +noall +answer
;; global options: +cmd
www.google.com.         299     IN      A       172.217.160.68

亦可關閉輸出註解,讓資訊更簡潔:

# 關閉輸出註解
dig +nocmd www.google.com +noall +answer
www.google.com.         299     IN      A       172.217.160.68

DNS 反向查詢

若要進行 DNS 反向查詢,可以加上 -x 參數並指定要進行反查的 IP 位址:

# DNS 反向查詢
dig -x 172.217.160.68
; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> -x 172.217.160.68
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17946
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;68.160.217.172.in-addr.arpa.   IN      PTR

;; ANSWER SECTION:
68.160.217.172.in-addr.arpa. 114 IN     PTR     tsa01s09-in-f4.1e100.net.

;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Sun Jul 19 20:30:55 CST 2020
;; MSG SIZE  rcvd: 94

指定 DNS 伺服器

若要自行指定要使用的 DNS 伺服器,可以使用 @ 加上 DNS 伺服器 IP 位址的方式來指定,例如若要使用 Google 的 8.8.8.8 DNS 伺服器,就可以這樣寫:

# 指定 DNS 伺服器
dig @8.8.8.8 www.google.com
; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> @8.8.8.8 www.google.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50489
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.google.com.			IN	A

;; ANSWER SECTION:
www.google.com.		215	IN	A	172.217.160.100

;; Query time: 8 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Mon Jul 20 08:12:31 CST 2020
;; MSG SIZE  rcvd: 59

查詢指定類型 DNS 記錄

dig 預設會查詢主機的 IPv4 位址(A 記錄),若要查詢其他類型的 DNS 記錄,可在完整主機名稱後方加上欲查詢的 DNS 記錄類型,常見的 DNS 記錄類型有 A、AAAA、MX、TXT、NS、CNAME 與 SOA 等。

例如查詢 google.com 網域的郵件伺服器(MX 記錄):

# 查詢 MX 類型的 DNS 記錄
dig google.com MX
; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> google.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59995
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;google.com.                    IN      MX

;; ANSWER SECTION:
google.com.             409     IN      MX      40 alt3.aspmx.l.google.com.
google.com.             409     IN      MX      50 alt4.aspmx.l.google.com.
google.com.             409     IN      MX      20 alt1.aspmx.l.google.com.
google.com.             409     IN      MX      30 alt2.aspmx.l.google.com.
google.com.             409     IN      MX      10 aspmx.l.google.com.

;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Sun Jul 19 20:20:36 CST 2020
;; MSG SIZE  rcvd: 147

若要查詢所有類型的 DNS 記錄,可將類型指定為 ANY:

# 查詢所有類型 DNS 記錄
dig www.google.com ANY
; <<>> DiG 9.11.3-1ubuntu1.12-Ubuntu <<>> www.google.com ANY
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5077
;; flags: qr rd ra; QUERY: 1, ANSWER: 9, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;www.google.com.                        IN      ANY

;; ANSWER SECTION:
www.google.com.         199     IN      A       64.233.189.99
www.google.com.         199     IN      A       64.233.189.106
www.google.com.         199     IN      A       64.233.189.147
www.google.com.         199     IN      A       64.233.189.105
www.google.com.         199     IN      A       64.233.189.103
www.google.com.         199     IN      A       64.233.189.104
www.google.com.         199     IN      AAAA    2404:6800:4008:c07::93
www.google.com.         199     IN      AAAA    2404:6800:4008:c07::6a
www.google.com.         199     IN      AAAA    2404:6800:4008:c07::69

;; Query time: 10 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Sun Jul 19 20:08:55 CST 2020
;; MSG SIZE  rcvd: 223

追蹤查詢路徑

當 DNS 的解析出現問題時,可加上 +trace 參數讓 dig 從根節點追蹤查詢路徑,釐清問題的所在:

# 從根節點追蹤查詢路徑
dig www.google.com +trace

尋找問題時,通常也會配合不同的 DNS 伺服器交叉比對查詢結果:

# 指定 DNS 伺服器,從根節點追蹤查詢路徑
dig @8.8.8.8 www.google.com +trace

dig 設定檔

使用者若有慣用的 dig 參數,可將參數設定寫在 ~/.digrc 這個設定檔中,這樣在執行 dig 的時候就會自動套用這些參數:

# 建立 dig 設定檔
echo "+noall +answer" > ~/.digrc

大量批次 DNS 記錄查詢

若要一次對大量的主機進行 DNS 記錄查詢,可以將所有的主機寫在一個文字檔案中,一行一個主機,再以 -f 參數指定輸入檔進行 DNS 查詢。

例如建立一個文字檔案 input.txt,內容如下:

google.com
ubuntu.com
tw.yahoo.com

然後進行大量批次 DNS 記錄查詢:

# 從檔案輸入進行批次查詢
dig -f input.txt

2016年9月8日 星期四

解決複製虛擬機Linux,網卡啟動失敗 Device eth0 does not seem to be present, delaying initialization

  利用 VirtualBox或是VMware 的"再製"功能,複製一台 Linux 虛擬主機,結果開機後發現網路卡未啟動,執行 ifup eth0 出現下列訊息。

 # ifup eth0
 
 Device eth0 does not seem to be present, delaying initialization.
  經查詢發現因為"再製"出來的虛擬機會變更新的 MAC Address,所以造成 Linux 判斷成另一張網卡,下列兩種方法任選一種就可以解決。

方法一:
 1) 我們可以先用下列指令查看系統目前抓到哪幾張網卡
 # cat /proc/net/dev
 Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:       0        0    0    0    0     0          0         0        0        0    0    0    0     0       0          0
  eth1:     0        0    0    0    0     0          0         0        0        0    0    0    0     0       0          0
 這裡可以發現網卡代號已經變成 eth1 

 2) 編輯 /etc/udev/rules.d/70-persistent-net.rules
 # vi /etc/udev/rules.d/70-persistent-net.rules
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:64:f9:37", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:64:f9:39", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

 可以將 eth1 修改為 eth0,重新開機。


 3) 編輯 /etc/sysconfig/network-scripts/ifcfg-eth0
 # vi /etc/sysconfig/network-scripts/ifcfg-eth0
 將"HWADDR="參數修改成正確的 MAC Address,或刪除此參數,若沒有這個參數應該在上一個步驟重新開機後會自動啟動網卡。

 4) 修改完成後,就可以順利啟動網卡。
 # ifup eth0


方法二:
 1) 我們可以先用下列指令查看系統目前抓到哪幾張網卡
 # cat /proc/net/dev
 Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
eth1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 這裡可以發現網卡代號已經變成 eth1

 2) 編輯 /etc/sysconfig/network-scripts/ifcfg-eth0
 # vi /etc/sysconfig/network-scripts/ifcfg-eth0
 DEVICE=eth0 -> 修改為 DEVICE=eth1
 HWADDR= -> 刪除或修改成正確的 MAC Address

 3) 因為裝置名稱已變更,所以 ifcfg-eth0 也要跟著更名
 # mv ifcfg-eth0 ifcfg-eth1

 4) 修改完成後,就可以順利啟動網卡。
 # ifup eth1

2014年5月9日 星期五

CentOS 5.9/6.4 中Samba 無法存取home directory

好久好久沒用samba了,想說做個練習。
於是我使用CentOS 6.4做個練習,當samba設定完後,發現我並不能連進去我的home directory。
除了我設定的路徑是可以存取的外,就是只有home directory 不能存取。
我做了很多嘗試,如: 可能新版,samba做了某些改變,降版到5.9(一樣的問題,不能解決),關掉防火牆和disable selinux(也不能解決問題)。

後來google很久爬文(看===以下內容),才發現這個問題,原來還是selinux的問題,即使關掉selinux,這似乎還是會有影響。因此做個記錄當作筆記。
===============
剛剛裝玩CentOS 6.0, 並且裝完samba server 後, 發現幾個問題.
1. system-config-samba 不見了.
解決方式: 原來是CentOS 6 以後, 將他移除了. 唉~ 只能手動修改 smb.conf 檔來設定.
2. 設完samba user 並且啟動samba service 後, 在windows XP 下卻看不到.
解決方式: 原來是linux 的firewall 搞鬼, ok, 用system-config-firewall 來允許samba 連接.
嗯, XP 中可以看到家目錄了, 但是卻無法連進去 ??!!
查了好久, 才知道是selinux 搞鬼. 記得在CentOS 5.x 時, 第一次啟動時都會問是否要enable selinux.
但是CentOS 6.0 卻沒有詢問, 害我忘記 selinux 的存在. Default 值是Enable 的.
本來想用system-config-securitylevel 來關閉selinux, 沒想到這個程式在CentOS 6.0 又被拿掉了, 是怎樣啦(翻桌!!) 一堆常用的東西都被拿掉.
想想算了, 找到selinux 的設定檔, 在/etc/selinux/config 中. 正想修改設定時, 想想, 改完後要重開機才能生效, 而我正在compile 其它程式, 還要幾個小時才能做完.
真的不想關機.
再想想其他方法好了. 後來在/etc/samba/smb.conf 看到說明.
原來只要執行
 
setsebool -P samba_enable_home_dirs on 

2013年7月18日 星期四

Linux系統下超級終端Minicom的使用方法

Linux下的Minicom的功能與Windows下的超級終端功能相似,適於在linux通過超級終端對嵌入式設備的管理以及對嵌入操作系統的升級,現寫出Minicom的使用手冊

Linux下的超級終端Minicom的使用手冊

  Linux下的Minicom的功能與Windows下的超級終端功能相似,適於在Linux通過超級終端對嵌入式設備的管理以及對嵌入操作系統的升級,現寫出Minicom的使用手冊

  配置Minicom和使用Minicom

  1.啟動Minicom

  以root權限登錄系統

  使用命令

  root –s則Minicom啟動,屏幕出現如下的界面|:

  ……………[configuration]……………………………………

  …… Filename and paths ………………………

  …… File transfer and protocols ………………

  …… Serial port setup …………………

  …… Modem and dialing …………………………

  …… Screen and keyboard …………

  …… Save setup as df1 …………………

  …… Save setup as…… …………………………

  …… Exit …………………………

  …… Exit from Minicom …………………………

  ………………………………

  2.設置serial port setup

  使用down箭頭選擇serial port setup,出現具體各選項的配置:

  A — Serial Device : /dev/ttyS0

  B — lockfile Location : /var/lock

  C — Calling Program :

  D — Callout Program:

  E — Bps/par/Bits : 9600 8N1

  F — Hardware Flow Control : YES

  G — Software Flow Control : NO

  Change with setting?

  將選項A的值設置為/dev/ttyS0 表示是串口1。

  將選項E的值設置為9600。

  設置過程中命令的使用,例如需要修改選項A的值,在Change with setting?選項後輸入A則光標轉移到A選項後,可以對A選項的值進行修改。

  3.設置Modem and dialing

  使用方向箭頭選中modem and dialing 項,則修改modem and dialing 選項中的配置項。

  需要修改的是去掉

   A — initing string ……:

   B — Reset string ……:

  K — Hang-up string ……三個配置項。

  4.選擇Save as df1

  選擇Save as df1選項將修改後的配置信息進行保存為默認的配置選項。

  5.Exit from Minicom

  選擇Exit from Minicom選項從配置菜單返回到命令行。

  6.重新啟動Minicom

  使用Minicom啟動Minicom在Linux下通過串口連接路由器,實現超級終端的功能。

2013年4月30日 星期二

How do I check and configure serial ports under Linux?



How do I check and configure serial ports under Linux for various purposes such as modem, connecting null modems or connect a dumb terminal?

Linux offers various tools. Linux uses ttySx for a serial port device name. For example, COM1 (DOS/Windows name) is ttyS0, COM2 is ttyS1 and so on.

Task: Display Detected System's Serial Support

Simple run dmesg command
$ dmesg | grep tty
Output:
[   37.531286] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[   37.531841] 00:0b: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[   37.532138] 0000:04:00.3: ttyS1 at I/O 0x1020 (irq = 18) is a 16550A

setserial command

setserial is a program designed to set and/or report the configuration information associated with a serial port. This information includes what I/O port and IRQ a particular serial port is using, and whether or not the break key should be interpreted as the Secure Attention Key, and so on. Just type the following command:
$ setserial -g /dev/ttyS[0123]
Output:
/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: 16550A, Port: 0x1020, IRQ: 18
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3
setserial with -g option help to find out what physical serial ports your Linux box has.

Linux serial console programs

Once serial ports identified you can configure Linux box using various utilities:
  1. minicom- The best friendly serial communication program for controlling modems and connecting to dump devices
  2. wvidial or other GUI dial up networking program - a PPP dialer with built-in intelligence.
  3. getty / agetty - agetty opens a tty port, prompts for a login name and invokes the /bin/login command.
  4. grub / lilo configuration - To configure serial port as the system console

iSCSI initiator configuration in RedHat Enterprise Linux 5


iSCSI initiator configuration in RedHat Enterprise Linux 5

The following post will discuss about iSCSI initiator configuration in RedHat Enterprise Linux 5, this method is also applicable to all RHEL5 derivatives. The iSCSI LUNs will be provided by an HP P4000 array.
First of all we need to get and install the iscsi-initiator-utils RPM package, you can use yum to get and install the package from any supported repository for CentOS or RHEL. You can also download the package from RedHat Network if you have a valid RHN account and your system doesn’t have internet connection.
[root@rhel5 ~]# rpm -ivh /tmp/iscsi-initiator-utils-6.2.0.871-0.16.el5.x86_64.rpm
Preparing...                ########################################### [100%]
   1:iscsi-initiator-utils  ########################################### [100%]
[root@rhel5 ~]#
[root@rhel5 ~]#rpm -qa | grep iscsi
iscsi-initiator-utils-6.2.0.871-0.16.el5
[root@rhel5 ~]# rpm -qi iscsi-initiator-utils-6.2.0.871-0.16.el5
Name        : iscsi-initiator-utils        Relocations: (not relocatable)
Version     : 6.2.0.871                         Vendor: Red Hat, Inc.
Release     : 0.16.el5                      Build Date: Tue 09 Mar 2010 09:16:29 PM CET
Install Date: Wed 16 Feb 2011 11:34:03 AM CET      Build Host: x86-005.build.bos.redhat.com
Group       : System Environment/Daemons    Source RPM: iscsi-initiator-utils-6.2.0.871-0.16.el5.src.rpm
Size        : 1960412                          License: GPL
Signature   : DSA/SHA1, Wed 10 Mar 2010 04:26:37 PM CET, Key ID 5326810137017186
Packager    : Red Hat, Inc. 
URL         : http://www.open-iscsi.org
Summary     : iSCSI daemon and utility programs
Description :
The iscsi package provides the server daemon for the iSCSI protocol,
as well as the utility programs used to manage it. iSCSI is a protocol
for distributed disk access using SCSI commands sent over Internet
Protocol networks.
[root@rhel5 ~]#
Next we are going to configure the initiator. The iSCSI initiator is composed by two services,iscsi and iscsid, enable them to start at system startup using chkconfig.
[root@rhel5 ~]# chkconfig iscsi on
[root@rhel5 ~]# chkconfig iscsid on
[root@rhel5 ~]#
[root@rhel5 ~]# chkconfig --list | grep iscsi
iscsi           0:off   1:off   2:on    3:on    4:on    5:on    6:off
iscsid          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@rhel5 ~]#
[root@rhel5 ~]#
Once iSCSI is configured start the service.
[root@rhel5 ~]# service iscsi start
iscsid is stopped
Starting iSCSI daemon:                                     [  OK  ]
                                                           [  OK  ]
Setting up iSCSI targets: iscsiadm: No records found!
                                                           [  OK  ]
[root@rhel5 ~]#
[root@rhel5 ~]# service iscsi status
iscsid (pid  14170) is running...
[root@rhel5 ~]#
From the P4000 CMC we need to add the server to the management group configuration like we would do with any other server.
The server iqn can be found in the file /etc/iscsi/initiatorname.iscsi.
[root@cl-node1 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:2551bf29b48
[root@cl-node1 ~]#
Create any iSCSI volumes you need in the P4000 arrays and assign them to the RedHat system. Then to discover the presented LUNs, from the Linux server run the iscsiadm command.
[root@rhel5 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.126.60
192.168.126.60:3260,1 iqn.2003-10.com.lefthandnetworks:mlab:62:lv-rhel01
[root@rhel5 ~]#
Restart the iSCSI initiator to make the new block device available to the operative system.
[root@rhel5 ~]# service iscsi restart
Stopping iSCSI daemon:
iscsid dead but pid file exists                            [  OK  ]
Starting iSCSI daemon:                                     [  OK  ]
                                                           [  OK  ]
Setting up iSCSI targets: Logging in to [iface: default, target: iqn.2003-10.com.lefthandnetworks:mlab:62:lv-rhel01, portal: 192.168.126.60,3260]
Login to [iface: default, target: iqn.2003-10.com.lefthandnetworks:mlab:62:lv-rhel01, portal: 192.168.126.60,3260]: successful
                                                           [  OK  ]
[root@rhel5 ~]#
Then check that the new disk is available, I used lsscsi but fdisk -l will do.
[root@rhel5 ~]# lsscsi
[0:0:0:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sda
[2:0:0:0]    disk    LEFTHAND iSCSIDisk        9000  /dev/sdb
[root@rhel5 ~]#
[root@rhel5 ~]# fdisk -l /dev/sdb 

Disk /dev/sdb: 156.7 GB, 156766306304 bytes
255 heads, 63 sectors/track, 19059 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table
[root@rhel5 ~]#
At this point the iSCSI configuration is done, the new LUNs will be available through a system reboot as long as the iscsi service is enabled.

iSCSI-target and client 設定


iSCSI-target 設定
建置時之環境:
 伺服器主機:192.168.10.101
 作業系統:CentOS 5.4 x86
 iscsi-target版本:iSCSI enterprise Target  1.4.20.2


一、iSCSI Server


1.安裝系統相關套件
 [root@localhost ~]#yum -y install kernel.x86_64 (或 kernel.i386 版本)
 [root@localhost ~]#yum -y install kernel-devel.x86_64 (版本需與kernel版本同)

 [root@localhost ~]#yum -y install openssl-devel



 [root@localhost ~]#yum -y install gcc



 [root@localhost ~]#yum -y install rpm-build


 [root@localhost ~]#reboot(安裝 kernel 必須重新啟動)


2.安裝 iscsitarget


 下載及安裝iscsi-target套件。

  [root@localhost ~]#tar -xvf iscsitarget-1.4.20.2.tar.gz



  [root@localhost ~]#cd iscsitarget-1.4.20.2



  [root@localhost ~]#make



  [root@localhost ~]#make install



3.建立 iSCSI 使用硬碟空間區塊(若使用單獨之分割區,例 /dev/md0 或 /dev/sdd,則此步驟略過)
 [root@localhost ~]# mkdir -p /iSCSI(可使用單一分割區或建立一目錄)
 [root@localhost ~]# dd if=/dev/zero of=/iSCSI/LUN0 bs=1024 count=40000(指定iscsi磁碟裝置為LUN0,大小為40M)
 [root@localhost ~]# dd if=/dev/zero of=/iSCSI/LUN1 bs=1024 count=8000000指定iscsi磁碟裝置為LUN1,大小為8G)

4.編輯 IET daemon 之設定檔(相關說明在/root/iscsitarget-1.4.19/README)


 (1)相關設定檔 :



  /etc/iet/ietd.conf



  /etc/iet/initiators.allow



  /etc/iet/targets.allow


 (2)編輯主要設定檔

  [root@localhost ~]# vi /etc/iet/ietd.conf


  主要修改以下幾項
# iqn.yyyy-mm.[:identifier]
# iqn通常為日期及網域反置(例tw.com.aa),加上storage標籤組合而成。
Target iqn.2010-03.tw.edu.tn.tnmr:storage.iscsi.iHD01
# 設定使用空間的路徑,LUN必須由編號0開始
#使用某一目錄 ( 例 /iSCSI ) 之空間時
Lun 0 Path=/iSCSI/LUN0,Type=fileio
Lun 1 Path=/iSCSI/LUN1,Type=fileio
#使用某一分割區 ( 例 /dev/md0 或 /dev/sdd ) 之空間時
Lun 0 Path=/dev/md0,Type=fileio
Lun 1 Path=/dev/sdd,Type=fileio
# Alias 可有可無
Alias iSCSI
MaxConnections 1
InitialR2T Yes
ImmediateData Yes

4.開啟防火牆 3260 port,重啟iptables (service iptables restart)


5.設定與啟動 iSCSI-Target 服務

 [root@centos1 ~]# chkconfig iscsi-target on



 [root@centos1 ~]# service iscsi-target start







二、iSCSI client端

(一)Linux OS

1.安裝

 [root@centos2 ~]# yum -y install iscsi-initiator-utils
2.編輯設定檔

 /etc/iscsi/iscsid.conf(一般可以用預設值)

 /etc/iscsi/initiatorname.iscsi (名稱須和Server端相同)

 [root@centos2 ~]# vi /etc/iscsi/initiatorname.iscs

          InitiatorName=iqn.2010-03.tw.idv.lu:storage.iscsi.vg01
(InitiatorName須和target 名稱相同)

3.啟動
(1)設定開機後自動啟動
[root@centos2 ~]# chkconfig iscsi on
(2)立刻啟動
[root@centos2 ~]# service iscsi start

4.列出與掛上 Server 上的 iSCSI Target

 [root@centos2 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.10.101

5.掛載

 [root@centos2 ~]# iscsiadm -m node -p 192.168.128.101 -T iqn.2010-03.tw.edu.tn.tnmr:storage.iscsi.iHD01 -l -d 10



 訊息:


 iscsiadm: updated 'node.session.err_timeo.lu_reset_timeout', '30' => '20'
:
:
Login to [iface: default, target: iqn.2010-4.tw.edu.tn.tnmr:storage.iscsi.iHD01,  portal: 192.168.10.101,3260]: successful
如果有以上的訊息 login to [xxx] : successful表示已正常連上。

6.列出本機上掛載的 iSCSI 項目
[root@centos2 ~]# iscsiadm --mode node 192.168.10.101:3260,1

iqn.2010-4.tw.edu.tn.tnmr:storage.iscsi.iHD01

7.查詢掛載位置


[root@centos2 ~]# tail -f /var/log/messages | grep "SCSI device" Feb 7 08:33:52 localhost kernel: SCSI device sdk: drive cache: write through
-->掛載為 /dev/sdk

8.列出目前硬碟狀態
[root@centos2 ~]# fdisk -l

9.進行硬碟作分割 (fdisk /dev/sdk)

10.格式化 (mkfs.ext3 /dev/sdk1)

11.掛載/dev/sdk1到預定的目錄上(例/mnt/iscsi )
[root@centos2 ~]# mkdir /mnt/iscsi
[root@centos2 ~]# mount /dev/sdc1 /mnt/iscsi

12.列出主機分割區使用情形
[root@centos2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00
:
:
/dev/sdk1 38M 4.5M 32M 13% /mnt/iscsi

2012年6月22日 星期五

CentOS 5.8 Netinstall – Network Installation 安裝方法


CentOS 5.8 netinstall 安裝參考文章

1. 請先注意網路線是接在哪張網卡上!!
2.下載netinstall版本iso
3. 安裝時,填上下載位置:
http:
ftp:
4. 之後設定參考網站:
架設 DNS Server CentOS 5.8 MyDNS 1.1.0 MyDNSConfig 3.0.1 正體中文-OC網友討論區-內文
http://www1.oc.com.tw/forums/forumview.asp?id=14&msgid=1099
參考網頁:
1. Centos 5.5 NetInstall | Percy's Blog
2. 架設 DNS Server CentOS 5.8 MyDNS 1.1.0 MyDNSConfig 3.0.1 正體中文-OC網友討論區-內文 

 =============================================================




If the purpose is to upgrade from an older version of CentOS to CentOS 5.8 then read following guide: Upgrade to CentOS 5.8 From 5.7 (5.6, 5.5, 5.4, 5.3, 5.2, 5.1, 5.0) guide
This is CentOS (The Community ENTerprise Operating System) 5.8 Linux Network installation (NetInstall) step-by-step walkthrough with screenshots.

Install CentOS 5.8 with NetInstall method

1. Download CentOS 5.8 Net Install (NetInstall) Image

Select mirror here:
i386 version
x86_64 version
Select ISO image
CentOS-5.8-i386-netinstall.iso
CentOS-5.8-x86_64-netinstall.iso

2. Burn Image to CD and Boot Computer Using CentOS 5.8 Installation CD

Check CentOS image MD5 sum and burn image to CD with your favourite CD burner. And boot computer using CentOS Installation CD.

3. Select Network Installation (NetInstall) on LiveCD Grub Menu or just press enter on CentOS Netinstall CD

Centos 5.8 Netinstall boot

4. Booting CentOS 5.8 Installer

5. Choose a Language

Choose a Language

6. Select keyboard type

Select keyboard type

7. Select Network Installation Method

Select Network Installation Method

8. Configure TCP/IP settings

Configure TCP/IP settings

9. Setup CentOS 5.8 Netinstall URL (Installation Web site name and CentOS directory)

Web site name:
mirror.centos.org
CentOS directory for i386:
/centos/5/os/i386
or
/centos/5.8/os/i386
CentOS directory for x86_64:
/centos/5/os/x86_64
or
/centos/5.8/os/x86_64
CentOS 5 Netinstall url (http setup)

10. Downloading Installer

Downloading Installer

11. Welcome to CentOS Screen

CentOS 5.8 Welcome to CentOS

12. Select Partitioning Type

Select “Create custom layout” option if you want modify partitions.
CentOS 5.8 Select partitioning type
Here you can modify partition layout.
CentOS 5.8 Partition layout

13. Boot Loader Configuration

CentOS 5.8 Bootloader setup

14. Network configuration

CentOS 5.8 Network setup

15. Select Time Zone

CentOS 5.8 Timezone setup

16. Set Root Password

CentOS 5.8 Set root password

17. Select packages for Installation

CentOS 5.8 Select installation type

18. Installing Selected Packages

CentOS 5.8 Installing selected packages

19. Installation Completed, Reboot

CentOS 5.8 Installation complete

20. Booted on Just Installed CentOS 5.8 Linux Server Command Line

CentOS 5.8 Server Installation Finished

2012年3月27日 星期二

命令列下寄送mail:本篇告訴你怎麼寄純文字、加附檔及HTML格式的mail


December 18, 2006


在Unix命令列下寄送mail

在命令列下寄送mail很多人都會,但是更多人不會。本篇告訴你怎麼寄純文字、加附檔及HTML格式的mail 。

在Unix的系統管理上我們常會把各式各樣指令的輸出導到檔案去,但是檔案在系統上,想看一下內容難免還得要登入上去。於是懶惰的人就會把這些輸出寄出來給相關的人,這樣就不需要還得連進去系統了。
在Unix下寄mail是一件很平常的事,有人可能會覺得這個有點老生常談,但事實是還是有人會來問我命令列下要怎麼寄 mail,而這個問題在網路上應該還是FAQ中的FAQ。
在Unix下最常被用來寄信的指令應該非mail莫屬,因為它普遍的存在各種不同版本不同平台的Unix系統上。或許你習慣用它的加強版mailx。不過這二個用起來差不多我也不清楚到底有什麼差別,知道的人跟我講一下吧。另外有一個指令叫mutt 它是一個功能相當強大的MUA軟體,如果你有安裝的話,也可以使用它來寄mail。
假設你想把/etc/hosts的內容傳到你的電腦上,你不需要使用ftp來把它抓到你的電腦,只要使用指令來將它寄給你自己。
# cat /etc/hosts |mailx -s 'hosts table' jerry@abc.com
許多人應該都知道要怎麼用,而且也很多人應該是這樣子用的。上面的指令並沒有錯,只是可以直接把檔案導入給 mailx,為什麼要cat給mailx呢?公司薪水給的又不多,實在沒必要多花時間在處理公事上,所以字能少打就少打吧。
# mailx -s 'hosts table' jerry@abc.com < /etc/hosts
-s(Subject)是主旨,如果主旨有空白字元的話,記得要用單引號(')或是雙引號(")括起來。最後一個參數是收件人,如果收件人有多個的時候要用逗號(,)分隔,如jerry@abc.com,jerry@abc.com.tw。
或者你在Linux下,而且又裝了mutt。你也可以使用mutt來寄信,mutt的參數和mail差不多。
# mutt -s 'hosts table' jerry@abc.com < /etc/hosts
可是這樣子寄,/etc/hosts的內容是在信裡面呀,我想把它變成附件可以嗎?當然可以,只要跟其他的程式配合就可以了。
# uuencode /etc/hosts hosts.txt | mailx -s 'hosts table' jerry@abc.com
利用uuencode把/etc/hosts編碼過後丟給mailx就可以了,uuencode第一個參數是要編碼的檔案,第二個參數是編碼後的檔名,在這裡就是附件的檔名。下面的例子示範了把tar檔變成附件直接寄出。
# tar cf - /etc/* | uuencode etc.tar | mailx -s 'hosts table' jerry@abc.com
如果你用的是mutt那就更簡單了。只要加個-a(attach file)
# echo '/etc/hosts'|mutt -a /etc/hosts -s 'hosts table' jerry@abc.com
有人會問說,Jerry,我不要只是寄純文字的mail,可以寄html格式的mail嗎?在我回答之前,可以容許我先打你一拳嗎?如果你有mutt(1.5.x 以上才行)的話要寄html格式的mail就很容易了(什麼,到這個時候還沒發現mutt有多好用嗎?還不快去裝起來。)。一行指令就可以搞定。
# mutt -e 'set content_type="text/html"' jerry@abc.com -s 'html format' < my.html
mutt允許我們對要寄出的mail修改它的檔頭(header),所以可以使用-e來設定檔頭的變數content_type為"text/html",這個變數名稱content_type和真正檔頭Content-type的字不一樣哦!不要搞錯了。最後再導入一個html格式的檔案給它就可以了。記住,-e後面那一串字不能錯哦!(1.5.x 以上才有這個變數。)
如果沒有mutt呢!裝一個,不然就繼續看下去。絕大多數的Unix系統應該都有內建sendmail,而sendmail有個參數-t可以達成我們的要求。看看下面的範例。
# echo 'Mime-Version: 1.0
> Content-type: text/html; charset="iso-8859-1"
> From: jerry@abc.com
> To: jerry@abc.com.tw
> Subject: test.......
>
> html file
> ' | sendmail -t
使用echo把檔頭和所要html的內容全部輸出給sendmail這樣子就可以了。不過我想沒人會真的在命令列這樣使用,多半會用在script裡面。下面提供一個script範例給你參考,主要的部份在被#包住的那個區塊,把你要的輸出做成html格式就可以了。
#!/bin/sh
fromuser=jerry@abc.com
touser=jerry@abc.com,abc,boss@abc.com
subject="`uname -n` df output"
sendmail="/usr/sbin/sendmail -t"
header="Mime-Version: 1.0
Content-type: text/html; charset="iso-8859-1"
From: $fromuser
To: $touser
Subject: $subject
"



footer="
"
{
echo "$header"
### replace your code here. ###
df -k |awk '/^//{$5=sprintf("%2d%",$5) ; print $0}'
###############################
echo "$footer"
} | $sendmail
下面二個script,第一個是shell script;第二個是perl script,你可以把要輸出的內容存成html檔,再用sendhtml直接寄出html格式的mail。寫的不怎麼樣,但最少可以使用啦!也給你一個想法做參考,你可以以此延伸然後寫一個符合你的script。
使用的方法如下,
sendhtml.pl "my subject" jerry@abc.com my_file.html
#!/bin/sh
## usage : sendhtml.sh subject To_User html_file
subject="$1"
touser="$2"
htmlfile="$3"
fromuser="jerry@abc.com"
sendmail="/usr/sbin/sendmail -t"
header="Mime-Version: 1.0
Content-type: text/html; charset="iso-8859-1"
From: $fromuser
To: $touser
Subject: $subject"
{
echo "$header"
cat "$htmlfile"
} | $sendmail
#!/usr/bin/perl -w
# usage : sendhtml.pl subject To_User html_file
my $sendmail = "/usr/sbin/sendmail";
my $fromuser = "jerry@abc.com";
$subject = $ARGV[0];
$touser = $ARGV[1];
$htmlfile = $ARGV[2];
$header="Mime-Version: 1.0
Content-type: text/html; charset="iso-8859-1"
From: $fromuser
To: $touser
Subject: $subjectn";
open(fd2, "| $sendmail -t");
print fd2 $header;
open(fd1, $htmlfile);
while(my $line=) {
print fd2 "$linen";
}
close(fd2);
close(fd1);
在寄附件的部份,能不用uuencode就不要用,因為uuencode+mailx所寄出來的mail並不會在檔頭的部份加入MIME編碼的訊息,而現在有越來越多的郵件程式不會正確讀取此種格式的mail。如yahoo, MSN....等webmail,在開啟這些mail時都會顯示亂碼,而不是正確的附檔,所以建議儘量使用別的程式來取代。
在命令列下寄mail的方法不只這些,如使用nail(已經改名叫mailx)或是使用perl、php....等也是可以,但以一般需求來講,我覺得這些應該已經夠了。如果你有什麼好的方法,歡迎你和大家分享。
由 m110092006 發表

Mutt發送html 格式的郵件方法


mutt配置
2009年11月10日 11:06
-i 參數把指定的文件內容當做正文
-a參數發附件

mutt -s "郵件主題" -i "正文文件名" 收件郵件


發送html郵件,一定要mutt 1.5.x版本,1.4不支持content_type變量, 用my_hdr加的gmail不支持
set content_type=text/html 一定要,不然識別不出html編碼,顯示為普通文本。 mutt1.5.x版本才支持
set charset="utf-8" 這個一定要設置,不然通過shell腳本crontab定時發信時顯示的編碼為unknown-8bit,識別不出編碼來
set content_type="text/html"
set editor="vim"

set envelope_from=yes 一定要設置,不然return-path顯示的是系統用戶名加域名,這可是我google,百度都用遍才找到的
set from="我愛你" 設置發件人
set move=no 不刪除郵件
set read_only=no
set realname="yourname"
set sendmail="/usr/sbin/sendmail -oem -oit"
set use_from=yes
set user_agent=no 發信時不顯示用戶代理信息

下面是我的配置,其餘沒有列出的參數使用默認設置
set content_type="text/html\;charset=utf-8"
set charset="utf-8"
set editor="vim"
set envelope_from=yes
set from="網站名字"
set read_only=no
set realname="test"
set send_charset="utf-8:us-ascii:iso-8859-1"
set sendmail="/usr/sbin/sendmail -oem -oit"
set use_from=yes
set user_agent=no

2012年3月23日 星期五

vim 支援 utf-8 中文,Putty 中文會有亂碼


解決了前述有關《有涯小札》的轉碼問題,《眾妙之門》的這一部份算是完全轉成了 UTF-8。下一步是其它網頁的轉碼問題。
事緣《眾妙之門》形成於 blog 還未流行的年代。當時我沒有用 WYSIWYG 的網頁編輯器,寫網頁是在文字編輯器中逐字逐字輸入的。現在《眾妙之門》中還保留著一些以 Big5 編碼的中文 HTML 文件(例如荒廢多時的 hohoSearch)。這些文件有待逐一以 iconv 程式轉碼。用 shell script 寫個 loop 來做,應該很容易完成。
問題是以後再要輸入中文 HTML 檔時怎麼辦。我的 Linux 以 Big5 編碼,而在 vim/gvim 輸入中文時,寫出來的也是 Big5 編碼的文件。總不能每次輸入完成之後,用 iconv 逐一轉換吧!幸好,偉大的 Google 很快給我答案。原來 vim/gvim 對 UTF-8 支援得很好,只是我這個井底之蛙沒有好好利用而已。以下的網頁提供了重要的啟示:
  1. vim 與 UTF-8 – 怕失憶筆記
  2. 讓 Vim 可以自己使用 UTF-8 & BIG5 – 小明網誌
  3. Vim 檔案編碼及格式 – wiki.gentoo.org.tw
  4. Vim documentation: mbyte
經理解消化之後,在自己的 .vimrc 加入了以下的設定,令 vim/gvim 遇到中文檔時,懂得選擇正確的編碼。而在建立新檔時,也自動以 utf-8 編碼:
“Default encoding
set fileencodings=utf-8,big5,gbk,latin1
set fileencoding=utf-8
實驗証明,這已能滿足大部份所需,讀寫都不成問題。最後,有時要強迫改變檔案的編碼,所以再加入以下設定:
“Hot key to switch between Big5 and UTF-8
set =^U
set =^B
map :set fileencoding=utf-8
map :set fileencoding=big5
以後便可以在 vim/gvim 裡按 ctrl-u 及 ctrl-b 來轉換編碼。
按:其實 gedit 也能自動選擇正確的編碼,不過在整體功能上,gedit 遠不及 vim/gvim(除了emacs 之外,又有哪個編輯器能及得上 vim/gvim?),所以不得不在 vim/gvim 上尋求解決之法。
----------------------------------------------------------
----------------------------------------------------------

Putty 中文會有亂碼Putty 中文會有亂碼

Putty 中文會有亂碼

Putty 進Fedora 中文會有亂碼??
Fedora 預設使用 UTF-8 編碼, 您用 putty 連入
可能會看到亂碼, 若改成 big5 編碼, 應該可以看到.

修改vim /etc/sysconfig/i18n 前二項設定如下:

vim /etc/sysconfig/i18n

LANG="zh_TW.Big5"
SUPPORTED="zh_TW.Big5:zh_TW:zh"

SYSFONT="latarcyrheb-sun16"
 


/etc/rc.dinit.d/i18n restart
Reference: 
http://yu-li-liang.blogspot.com/2010/10/putty.html 

AI 待觀察素材

UI UX Pro Max Design Intelligence https://www.uupm.cc/ 如何做出你的AI員工-網路版 上課簡報 https://www.4rich.org/ai/how2ai-v8.html