顯示具有 linux的基本 標籤的文章。 顯示所有文章
顯示具有 linux的基本 標籤的文章。 顯示所有文章

2025年2月6日 星期四

掛載 CentOS 8 Linux ISO 來當作本地倉庫,以安裝SNMP來示範。

由於舊版的Linux,可能因為原廠停止維護支援,已經無法線上yum or dnf安裝相關套件。
我們可以改用掛載 CentOS 8 ISO 來當作本地倉庫,就可以進行yum or dnf安裝。但建議盡量優先安裝新版,比較沒有資安漏洞或程式老舊的問題。

第一部分: 掛載 CentOS 8 Linux ISO 來當作本地倉庫,安裝套件。
步驟一:掛載 CentOS 8 ISO
1.建立掛載目錄
#mkdir -p /mnt/centos8

2.掛載光碟機
#mount /dev/sr0 /mnt/centos8

或是掛載ISO(擇一)
#mount -o loop /path/to/CentOS-8.4.2105-x86_64-dvd1.iso /mnt/centos8

3.確認掛載成功
#ls /mnt/centos8

步驟二:建立本地倉庫
1.產生倉庫設定檔
#vi /etc/yum.repos.d/centos8-local.repo

加入以下內容:
-----------------------------------------------------------
[centos8-local]
name=CentOS 8 Local Repo
baseurl=file:///mnt/centos8/BaseOS/
enabled=1
gpgcheck=0

[centos8-appstream]
name=CentOS 8 AppStream Repo
baseurl=file:///mnt/centos8/AppStream/
enabled=1
gpgcheck=0
-----------------------------------------------------------

2.清除快取並更新倉庫

#dnf clean all
#dnf makecache
#dnf repolist

如果倉庫成功掛載,你應該會看到 centos8-local 和 centos8-appstream。


步驟三:安裝 net-snmp

#dnf install -y net-snmp  net-snmp-utils

這樣就會從 掛載的 CentOS 8 ISO 來安裝 net-snmp,而不需要透過網路下載。

=============
第二部分: SNMP安裝完後的設定和使用。
1.檢查 snmpd.conf 設定
vim /etc/snmp/snmpd.conf


snmpd.conf 原廠設定值僅供參考,請了解各設定值的意義,再行設定。


2. 檢查 SELinux (如果啟用了)
#getenforce
如果返回 Enforcing,可以先嘗試暫時關閉:

#setenforce 0
然後再測試 SNMP 是否能被監控主機訪問。如果這樣解決了問題,可能需要配置 SELinux 政策來允許 SNMP。


3.
 檢查防火牆設定

查看防火牆規則:
#firewall-cmd --list-all

如果防火牆開啟了 (firewalld 是 running),你需要允許 UDP 161 埠:
#firewall-cmd --add-port=161/udp --permanent
#firewall-cmd --reload


或者允許 SNMP 服務:
#firewall-cmd --add-service=snmp --permanent
#firewall-cmd --reload

4. 測試從監控主機連線

待補...







2023年11月27日 星期一

查看 Ubuntu 版本資訊的 6 種方法

自從CentOS 6改版後,很多指令,變得很陌生,都要再查一下。
當然啦,本身也是少用,不夠熟的關係。所以也沒有,跟著新版的學習。

連查看新版的方式,也要查....。純做個紀錄留存。


查看 Ubuntu 版本資訊的 6 種方法


使用 lsb_release -a 查詢 Ubuntu 版本資訊
使用 cat /etc/lsb-release 查詢 Ubuntu 版本資訊
使用 cat /etc/os-release 查詢 Ubuntu 版本資訊
使用 hostnamectl 查詢 Ubuntu 版本資訊
使用 uname -a 查詢 Ubuntu 版本資訊
使用 cat /etc/issue 查詢 Ubuntu 版本資訊

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

2013年6月18日 星期二

Mounting a hard disk image including partitions using Linux


Mounting a hard disk image including partitions using Linux


A while ago I thought it would be a good idea to make a backup of my Linux server by just dumping the complete disk to a file. In retrospect, it would have been much easier had I just dumped the individual filesystems.
When I finally got around to using this backup, long after the 10GB disk had perished I realized that to use the loopback device to mount a filesystem it actually needs a filesystem to mount. What I had was a disk image, including partition table and individual partitions. To further complicate matters the data partition was also not the first partition inside this image.
For reference, I created this image using the Unix ‘dd’ tool:
# dd if=/dev/hda of=hda.img
30544113+0 records in
30544113+0 records out
# ls -lh
-rw-r--r-- 1 root    root  9.6G 2008-01-22 14:12 hda.img
I followed the instructions on http://www.trekweb.com/~jasonb/articles/linux_loopback.html to try and mount the partitions inside the disk image, but ran into two problems.
To mount a partition inside the disk image you need to calculate the offset of where the partition starts. You can use fdisk to show this information to you, but you need to specify the number of cylinders if you are using a disk image.
You then also need to multiply the start and end numbers with the calculated sectors to get a byte offset.
I found another tool more useful for this task, called parted. If you are using Ubuntu, you can install it with ‘apt-get install parted’
# parted hda.img
GNU Parted 1.7.1
Using /data/rabbit/disk_image/test2
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit
Unit?  [compact]? B
(parted) print
Disk /data/rabbit/disk_image/test2: 10262568959B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start        End           Size         Type     File system  Flags
1      32256B       106928639B    106896384B   primary  ext3         boot
2      106928640B   1184440319B   1077511680B  primary  linux-swap
3      1184440320B  10256924159B  9072483840B  primary  ext3
(parted) quit
Now we have the offsets and we can use those to mount the filesystems using the loopback device:
#mount -o loop,ro,offset=32256 hda.img /mnt/rabbit
That mounted the first partition, the ‘boot’ partition, but this didn’t have the data on it that I was looking for. Lets try to mount partition number 3.
#umount /mnt/rabbit
#mount -o loop,ro,offset=1184440320 test2 /mnt/rabbit
#mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail  or so
Oops, that doesn’t look right. According the article referred to above if you are using a util-linux below v2.12b then you cannot specify an offset higher than 32bits. I’m using util-inux 2.13 which shouldn’t have that problem, and besides, my offset is well below the 32bit limit.
The article also offers an alternative loopback implementation that supports mounting partitions within an image, but that requires patching and recompiling your kernel which I would rather not do.
Instead I decided to extra ct the filesystem from the image which would then allow me to mount it without specifying an offset.
Doing this is quite straightforward with ‘dd’. You need to give ‘dd’ a skip count, or, how far into the source to start copying, and a count, how much to copy.
Here you can either use the single byte offsets retrieved with parted or divide them by 512 and let ‘dd’ use 512 byte blocks. Copying just one byte at a time takes a very long time, so I suggest using a larger block size.
Here is the command I used to extract my filesystem. Skip is 2313360 (1184440320/512) and Count is 17719695 (9072483840/4)
#dd if=hda.img of=hda3.img bs=512 skip=2313360 count=17719695
17719695+0 records in
17719695+0 records out
9072483840 bytes (9.1 GB) copied, 485.679 seconds, 18.7 MB/s
After extracting the filesystem I was able to mount it without any problems.
# mount -o loop hda3.img /mnt/rabbit/
# df -h /mnt/rabbit
Filesystem            Size  Used Avail Use% Mounted on
/data/rabbit/image/hda3.img
8.4G  6.3G  1.7G  80% /mnt/rabbit

Loop-mounting partitions from a disk image

Loop-mounting partitions from a disk image
Update: it seems that kpartx pretty much does all of the below. Thanks to Faidon Liambotis for the pointer.
Every now and then, I have a disk image (as produced by cat, pv, or dd) and I need to access separate partitions. Unfortunately, the patch allowing partitions on loop devices to be accessed via their own device nodes does not appear to be in the latest (Debian) 2.6.18 kernels — the loop module does not have a max_part parameter, according to modinfo.
So this time I sat down to come up with a recipe on how to access the partitions, and after some arithmetic and much swearing at disk manufacturers, and especially the designers of the msdos partition table type, I think I have found the solution, and the urge to document it for posterity.
It's all about the -o parameter to losetup, which specifies how many bytes into the disk a given partition starts. Getting this number isn't straight forward. Well, it is, if you know how, which is why I am writing this.
Let's take a look at a partition table, with sectors as units:
$ /sbin/fdisk -lu disk.img
You must set cylinders.
You can do this from the extra functions menu.

Disk disk.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes

      Device Boot      Start         End      Blocks   Id  System
disk.imgp1   *          63       96389       48163+  83  Linux
disk.imgp2           96390     2056319      979965   82  Linux swap / Solaris
disk.imgp3         2056320    78140159    38041920    5  Extended
disk.imgp5         2056383     3052349      497983+  83  Linux
disk.imgp6         3052413    10859939     3903763+  83  Linux
disk.imgp7        10860003    68372639    28756318+  83  Linux
disk.imgp8        68372703    76180229     3903763+  83  Linux
disk.imgp9        76180293    78140159      979933+  83  Linux

The first few lines is fdisk complaining not being able to extract the number of cylinders, since it has to operate on a file which does not provide an ioctl interface.
The first important data are the units, which are stated to be 512 bytes per sector. We take note of this value as the factor for use in the next operation.
Let's say we want to access the 7th partition, which is 10860003 sectors into the disk, according to the fdisk output. We know that each sector is 512 bytes, so:
10860003 * 512 = 5560321536

Passing this number to losetup produces the desired result:
# losetup /dev/loop0 disk.img -o $((10860003 * 512))
# file -s /dev/loop0
/dev/loop0: Linux rev 1.0 ext3 filesystem data
# mount /dev/loop0 /mnt
[...]
# umount /mnt
# losetup -d /dev/loop0

If the partition really holds a normal filesystem, you can also let mount set up the loop device, and manage it automatically:
# mount -o loop,offset=$((10860003 * 512)) disk.img /mnt
[...]
# umount /mnt

And since there's aparently no means to automate the whole process for an entire disk, I hacked up plosetup. Enjoy:
# plosetup lapse.hda .
I: partition 1 of lapse.hda will become ./lapse.hda_p1 (/dev/loop0)...
I: plosetup: skipping partition 2 of type 82...
I: plosetup: skipping partition 3 of type 5...
I: partition 5 of lapse.hda will become ./lapse.hda_p5 (/dev/loop1)...
I: partition 6 of lapse.hda will become ./lapse.hda_p6 (/dev/loop2)...
I: partition 7 of lapse.hda will become ./lapse.hda_p7 (/dev/loop3)...
I: partition 8 of lapse.hda will become ./lapse.hda_p8 (/dev/loop4)...
I: partition 9 of lapse.hda will become ./lapse.hda_p9 (/dev/loop5)...
# ls -l
total 0
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p1 -> /dev/loop0
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p5 -> /dev/loop1
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p6 -> /dev/loop2
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p7 -> /dev/loop3
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p8 -> /dev/loop4
lrwxrwxrwx 1 root root 10 2006-10-20 13:25 lapse.hda_p9 -> /dev/loop5
# plosetup -c .
# ls -l
total 0

(this post is dedicated to Penny for no other reason than the tunes I am listening to right now)
NP: Fly My Pretties / The Return of Fly My Pretties
Update: Be careful about the $((...)) style arithmetic. dash manages to overflow at 32bit. zsh and bash seem to get it right. If in doubt, use perl or a calculator.

2013年4月24日 星期三

設定 /etc/resolv.conf 檔案


此檔案可用來設定 DNS 用戶端要求名稱解析時,所定義的各項內容。我們分別來看一個完整的resolv.conf的檔案:

domain twnic.com.tw
nameserver 192.168.10.1
nameserver 192.168.2.5
search twnic.com.tw twnic.net.tw

“domain”指定本地的網域名稱,如果查詢時的名稱沒有包含小數點,則會自動補上此處的網域名稱為字尾再送給DNS伺服器。
“nameserver”指定用戶端要求進行名稱解析的 nameserver IP位址,在此可指定多部DNS伺服器,則用戶端將會依序提出查詢要求。

“search”這個選項為非必要選項,而功能在於若使用者指定主機名稱查詢時,所需要搜尋的網域名稱。例如,當我們設 “search twnic.com.tw”時,當DNS伺服器在做名稱解析過程中,無法對輸入的名稱,例如pc1,找出相對應的IP時,則DNS會利用search的設定值加上需查詢的名稱,即pc1.twnic.com.tw來進行解析,解析失敗時則會嘗試pc1.twnic.net.tw。

需要注意的是當我們想嘗試多種在沒有包含小數點,於字尾補上所需要搜尋的網域名稱時,我們會在"search"中指定幾種組合給DNS伺服器,而不能在"domain"中指定。因為“domain”是指定本地的網域名稱,而搜尋時也以“domain”為優先嘗試,如果失敗之後才會嘗試"search"中的組合。

Linux - 設定TimeZone


轉載於: http://linux-guys.blogspot.tw/2011/02/linux-timezone.html


第一種
查看目前時區
[root@darwin-test ~]# date
Wed Feb  9 05:20:22 EST 2011

[root@darwin-test ~]# cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="America/New_York"   //目前是New York時區
UTC=true
ARC=false

暫時設定台灣時區
[root@darwin-test ~]# export TZ='Asia/Taipei'
[root@darwin-test ~]# date
Wed Feb  9 18:22:24 CST 2011

永久設定時區
[root@darwin-test ~]# system-config-date
[root@darwin-test ~]# cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Taipei"
UTC=true
ARC=false

[root@darwin-test ~]# date
Wed Feb  9 18:26:16 CST 2011

另一作法-永久設定時區
編輯家目錄.profile or $HOME/.bash_profile
#vi $HOME/.profile
內容如下
export TZ='Asia/Taipei'

另一命令可供參考
[root@darwin-test ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5
Please select a country.
 1) Afghanistan           18) Israel                35) Palestine
 2) Armenia               19) Japan                 36) Philippines
 3) Azerbaijan            20) Jordan                37) Qatar
 4) Bahrain               21) Kazakhstan            38) Russia
 5) Bangladesh            22) Korea (North)         39) Saudi Arabia
 6) Bhutan                23) Korea (South)         40) Singapore
 7) Brunei                24) Kuwait                41) Sri Lanka
 8) Cambodia              25) Kyrgyzstan            42) Syria
 9) China                 26) Laos                  43) Taiwan
10) Cyprus                27) Lebanon               44) Tajikistan
11) East Timor            28) Macau                 45) Thailand
12) Georgia               29) Malaysia              46) Turkmenistan
13) Hong Kong             30) Mongolia              47) United Arab Emirates
14) India                 31) Myanmar (Burma)       48) Uzbekistan
15) Indonesia             32) Nepal                 49) Vietnam
16) Iran                  33) Oman                  50) Yemen
17) Iraq                  34) Pakistan
#? 43
The following information has been given:
        Taiwan
Therefore TZ='Asia/Taipei' will be used.
Local time is now:      Wed Feb  9 18:21:13 CST 2011.
Universal Time is now:  Wed Feb  9 10:21:13 UTC 2011.
Is the above information OK?
1) Yes
2) No
#? 1
You can make this change permanent for yourself by appending the line
        TZ='Asia/Taipei'; export TZto the file '.profile' in your home directory;
then log out and log in again.
Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Taipei

現在要做的事情就是按照提示,把TZ='Asia/Taipei'; export TZ   添加到.profile中(bash對應加到.bash_profile)。


tzselect命令用於選擇時區。要注意的是tzselect只是幫我們把選擇的時區顯示出來,並不會實際生效,也就是說它僅僅告訴我們怎麼樣去設置環境變量TZ。

如果你要永久更改時區,按照tzselect命令提示的信息,在.profile或者/etc/profile中設置正確的TZ環境變量並導出。還有另外一種更改時區的方法就是直接更改系統配置文件/etc/sysconfig/clock,然後修改符號鏈接/etc/locatime對應的文件,詳見示例三。

第二種

示例三 通過更改配置文件來修改時區
[root@new55 ~]# cat /etc/sysconfig/clock
# The ZONE parameter is only evaluated by system-config-date.
# The timezone of the system is defined by the contents of /etc/localtime.
ZONE="Asia/Shanghai"
UTC=true
ARC=false
[root@new55 ~]#
修改linux系統時區
    1) 可修改/etc/sysconfig/clock
        ZONE=Asia/Shanghai ( 查/usr/share/zoneinfo 下面的文件。 )
        UTC=false ( 硬件時鐘是否為UTC 或者說GMT 時鐘。 )
        ARC=false (如果是在Alpha 機器上,則設置為true 。 )
    (把硬件時鐘設置為UTC 的好處就是他能自動設置夏時制,缺點是,在安裝有多重操作系統啟動的機器上,在另外的操作系統上時鐘會錯誤。 )
    2) rm /etc/localtime
        Zhy: 這個文件是個符號鏈接?如果是在系統安裝時就設置好的話,就是個普通文件。
    3) 以上海為例:
        ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime



第三種

變更 Linux 系統預設時區(timezone)
1. 使用 root 帳號登入終端機
2. 執行 date 指令,此時會出現類似 Wed Jan 27 14:11:29 CST 2010 的訊息,其中 CST 就是目前系統預設時區
3. 切換到 /usr/share/zoneinfo 目錄,其中有所有時區(timezone)的列表, Taipei 時區在 Asia 下
4.  執行 mv /etc/localtime  /etc/localtime-old 備份目前設定
5.  執行 ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime 將欲使用的時區 softlink 到 /etc/localtime
6.  修改 /etc/sysconfig/clock 檔案內容,改為 ZONE="Asia/Taipei"
7.  執行 /sbin/hwclock --systohc 同步硬體時鐘





AD常用指令

●本機指令 ● AD 指令 ● PowerShell 指令 --------------------------------------------------- 抓取使用者在 AD 相關設定 Gpresult /R 抓取電腦本機在 AD 相關設定 Gpres...