ArchLinux 執行 iptables Firewall

參考網站:iptables – ArchWiki
啟動 iptables & ip6tables
# systemctl start iptables
# systemctl start ip6tables

建立 iptables 規則
# cp /etc/iptables/empty.rules /etc/iptables/iptables.rules
# touch /etc/iptables/ip6tables.rules

開機時啟動 iptables & ip6tables
# systemctl enable iptables
ln -s ‘/usr/lib/systemd/system/iptables.service’ ‘/etc/systemd/system/multi-user.target.wants/iptables.service’
# systemctl enable ip6tables
[@more@]底下以 IPv4 為例
設定防火牆規則
# iptables -nvL –line-numbers
Chain INPUT (policy DROP 18 packets, 1042 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1        0     0 ACCEPT     all  —  lo     *       0.0.0.0/0            0.0.0.0/0
2        0     0 DROP       all  —  *      *       0.0.0.0/0            0.0.0.0/0            state INVALID
3        0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:!0x17/0x02 state NEW
4        0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x3F/0x00
5        0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x03/0x03
6        0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x06/0x06
7        0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x05/0x05
8        0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x11/0x01
9        0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x30/0x20
10       0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x18/0x08
11       0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x3F/0x29
12       0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x3F/0x37
13       0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x3F/0x3F
14       0     0 DROP       tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x3F/0x01
15     107  7340 ACCEPT     all  —  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
16       0     0 ACCEPT     tcp  —  *      *       192.168.1.0/24       0.0.0.0/0            tcp dpt:22
17       0     0 ACCEPT     tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80
18       0     0 ACCEPT     tcp  —  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:443
19       0     0 ACCEPT     icmp —  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 8
20       0     0 ACCEPT     icmp —  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 0

Chain FORWARD (policy DROP 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 1 packets, 64 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1        0     0 ACCEPT     all  —  *      lo      0.0.0.0/0            0.0.0.0/0
2      100 16760 ACCEPT     all  —  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED

將目前的規則寫入到 /etc/iptables/iptables.rules
# iptables-save > /etc/iptables/iptables.rules

重新載入防火牆規則
# systemctl reload iptables
# iptables-restore < /etc/iptables/iptables.rules

# cat /etc/iptables/iptables.rules
# Generated by iptables-save v1.4.21 on Mon Sep 29 23:06:35 2014
*mangle
:PREROUTING ACCEPT [49:3160]
:INPUT ACCEPT [49:3160]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [51:7732]
:POSTROUTING ACCEPT [51:7732]
COMMIT
# Completed on Mon Sep 29 23:06:35 2014
# Generated by iptables-save v1.4.21 on Mon Sep 29 23:06:35 2014
*filter
:INPUT DROP [4:124]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state INVALID -j DROP
-A INPUT -p tcp -m tcp ! –tcp-flags FIN,SYN,RST,ACK SYN -m state –state NEW -j DROP
-A INPUT -p tcp -m tcp –tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
-A INPUT -p tcp -m tcp –tcp-flags FIN,SYN FIN,SYN -j DROP
-A INPUT -p tcp -m tcp –tcp-flags SYN,RST SYN,RST -j DROP
-A INPUT -p tcp -m tcp –tcp-flags FIN,RST FIN,RST -j DROP
-A INPUT -p tcp -m tcp –tcp-flags FIN,ACK FIN -j DROP
-A INPUT -p tcp -m tcp –tcp-flags ACK,URG URG -j DROP
-A INPUT -p tcp -m tcp –tcp-flags PSH,ACK PSH -j DROP
-A INPUT -p tcp -m tcp –tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,PSH,URG -j DROP
-A INPUT -p tcp -m tcp –tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,ACK,URG -j DROP
-A INPUT -p tcp -m tcp –tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN,SYN,RST,PSH,ACK,URG -j DROP
-A INPUT -p tcp -m tcp –tcp-flags FIN,SYN,RST,PSH,ACK,URG FIN -j DROP
-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -s 192.168.1.0/24 -p tcp -m tcp –dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp –dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp –dport 443 -j ACCEPT
-A INPUT -p icmp -m icmp –icmp-type 8 -j ACCEPT
-A INPUT -p icmp -m icmp –icmp-type 0 -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
COMMIT
# Completed on Mon Sep 29 23:06:35 2014
# Generated by iptables-save v1.4.21 on Mon Sep 29 23:06:35 2014
*nat
:PREROUTING ACCEPT [4:124]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
COMMIT
# Completed on Mon Sep 29 23:06:35 2014

使用 LEMP for Raspberry Pi 版會出現下面的錯誤訊息
iptables v1.4.21: can’t initialize iptables table `filter’: Table does not exist (do you need to insmod?)

Raspberry Pi 測試 – 成為 WiFi AP

參考網站:
Download Arch Linux Raspberry Pi WiFi Access Point Image – Hayden James

下載網站:
https://sourceforge.net/projects/archwipi/files/latest/download

預設登入帳號及密碼:root / archwipi

請更改密碼
# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
[@more@]
更換成台灣的 Server
# sed -i ‘s/^Server/#Server/’ /etc/pacman.d/mirrorlist
# sed -i ’53s/# Server/Server/g’ /etc/pacman.d/mirrorlist

更新套件庫
#
pacman -Syy
:: Synchronizing package databases…
 core                                        159.0 KiB  3.11M/s 00:00 [######################################] 100%
 extra                                         2.2 MiB  4.62M/s 00:00 [######################################] 100%
 community                                     2.4 MiB  5.11M/s 00:00 [######################################] 100%
 alarm                                        29.0 KiB  14.1M/s 00:00 [######################################] 100%
 aur                                          61.7 KiB  15.1M/s 00:00 [######################################] 100%

安裝所需套件
# pacman -S pssh vim mlocate dnsutils

設定時區
# date
Sun Sep 28 09:13:30 MDT 2014
# ls -l /etc/localtime
lrwxrwxrwx 1 root root 34 Aug 13  2013 /etc/localtime -> /usr/share/zoneinfo/America/Denver

刪除舊有設定
# rm -rf /etc/localtime

連結到 Asis/Taipei
# ln -s /usr/share/zoneinfo/Asia/Taipei /etc/localtime

# timedatectl set-timezone Asia/Taipei
# date
Sun Sep 28 23:16:19 CST 2014

設定中文化環境,加入 en_US.UTF-8 和 zh-TW.UTF-8
# sed -i ‘s/#en_US.UTF-8/en_US.UTF-8/’ /etc/locale.gen
# sed -i ‘s/#zh_TW.UTF-8/zh_TW.UTF-8/’ /etc/locale.gen

產生 locale.gen 內指定的語系
locale-gen
Generating locales…
  en_US.UTF-8
  zh_TW.UTF-8
Generation complete.

設定預設語系
# echo ‘LANG=”en_US.UTF-8″‘ > /etc/locale.conf

檢視設定
# grep -v ^# /etc/locale.gen
en_US.UTF-8 UTF-8
zh_TW.UTF-8 UTF-8

更新已安裝程式
# pacman -Syu

超頻
# vim /boot/config.txt
#Custom overclocking: http://haydenjames.io/raspberry-pi-safe-overclocking-settings/

##Overclock – Option 1: Low freq minimum & no over voltage (keeps Pi cool 24/7!)
arm_freq=800
arm_freq_min=600
core_freq=300
sdram_freq=500
boot_delay=0
disable_splash=1

##Overclock Option – 2: High freq maximums & over voltage (usually runs under 60C)
#arm_freq=1000
#core_freq=500
#sdram_freq=500
#over_voltage=6
#boot_delay=0
#disable_splash=1

##The lowest gpu_mem setting of 16MB (NoGUI)
gpu_mem=16

改成
#Custom overclocking: http://haydenjames.io/raspberry-pi-safe-overclocking-settings/

##Overclock – Option 1: Low freq minimum & no over voltage (keeps Pi cool 24/7!)
#arm_freq=800
#arm_freq_min=600
#core_freq=300
#sdram_freq=500
#boot_delay=0
#disable_splash=1

##Overclock Option – 2: High freq maximums & over voltage (usually runs under 60C)
arm_freq=1000
core_freq=500
sdram_freq=500
over_voltage=6
boot_delay=0
disable_splash=1

##The lowest gpu_mem setting of 16MB (NoGUI)
gpu_mem=16

重新啟動電腦
# systemctl reboot

無線網路 SSID及密碼:ArchWiPi / 1010101010

更改無線網路密碼
# vim /usr/lib/systemd/system/create_ap.service
[Unit]
Description=Create AP Service

[Service]
Type=simple
ExecStart=/usr/bin/bash create_ap wlan0 eth0 ArchWiPi 1010101010
KillSignal=SIGINT
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

檢查 CPU 速度和溫度,可以執行
# cd /root;./bcmstat.sh

使用瀏覽器來觀看:http://192.168.12.1:8080/archwipi

 (powered by Monitorix)

系統開啟的服務
# netstat -antulp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      344/monitorix-httpd
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN      342/dnsmasq
tcp        0      0 192.168.12.1:53         0.0.0.0:*               LISTEN      342/dnsmasq
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      119/dropbear
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           136/avahi-daemon: r
udp        0      0 127.0.0.1:53            0.0.0.0:*                           342/dnsmasq
udp        0      0 192.168.12.1:53         0.0.0.0:*                           342/dnsmasq
udp        0      0 0.0.0.0:67              0.0.0.0:*                           342/dnsmasq
udp        0      0 0.0.0.0:68              0.0.0.0:*                           384/dhcpcd
udp        0      0 0.0.0.0:40054           0.0.0.0:*                           136/avahi-daemon: r

ArchLinux 更新時出現 ignoring package upgrade 訊息

使用 pacman -Syu 更新時,出現下面的警告訊息
# pacman -Syu
:: Synchronizing package databases…
 core is up to date
 extra is up to date
 community is up to date
 alarm is up to date
 aur is up to date
:: Starting full system upgrade…
warning: linux-firmware: ignoring package upgrade (20140603.a4f3bc0-1 => 20141009.0e5f637-1)
warning: linux-sun7i: ignoring package upgrade (3.4.90-4 => 3.4.90-5)
warning: uboot-cubieboard2: ignoring package upgrade (2014.04-8 => 2014.04-10)
 there is nothing to do[@more@]看起來似乎是 linux-firmware / linux-sun7i / uboot-cubieboard2 這三個套件被設定成不能夠更新

# grep IgnorePkg /etc/pacman.conf
# Pacman won’t upgrade packages listed in IgnorePkg and members of IgnoreGroup
IgnorePkg   = linux-sun7i linux-firmware uboot-cubieboard2

原來是這一個 ArchLinux 的版本有設定這三個套件不做更新。

因為我目前用的這一個版本是特別製作給 BerryBoot 使用的版本,所以不是很了解,為什麼要特別限定這三個套件不做更新!

LEMP for Raspberry Pi

如果覺得自己修改 RASPBIAN 很麻煩,或自己從 ArchLinux 安裝 LNMP(Linux Nginx + MariaDB+PHP) 很辛苦,可以考慮下載由 Hayden James 製作的 LEMP for Raspberry Pi

LEMP for Raspberry Pi 網站:
http://haydenjames.io/download-lemp-raspberry-pi-nginx-mariadb-mysql-php/

下載網站:
http://sourceforge.net/projects/lemp-raspberry-pi/files/latest/download[@more@]預設登入的帳號及密碼:root / root
# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

設定時區
# date
Sun Sep 28 09:13:30 MDT 2014
# ls -l /etc/localtime
lrwxrwxrwx 1 root root 34 Aug 13  2013 /etc/localtime -> /usr/share/zoneinfo/America/Denver

刪除舊有設定
# rm -rf /etc/localtime

連結到 Asis/Taipei
# ln -s /usr/share/zoneinfo/Asia/Taipei /etc/localtime

# timedatectl set-timezone Asia/Taipei
# date
Sun Sep 28 23:16:19 CST 2014

更換成台灣的 Server
# sed -i ‘s/^Server/#Server/’ /etc/pacman.d/mirrorlist
# sed -i ’53s/# Server/Server/g’ /etc/pacman.d/mirrorlist

安裝的 Nginx Web Server 版本
# pacman -Qi nginx | grep Version
Version        : 1.6.0-5

安裝的 PHP 版本
# pacman -Qi php | grep Version
Version        : 5.5.14-1

安裝的 MariaDB SQL Server 版本
# pacman -Qi mariadb | grep Version
Version        : 10.0.12-1

更新套件庫
# pacman -Syy

更新已安裝的套件
# pacman -Syu

Niginx Web Server 預設網頁根目錄
/usr/share/nginx/html

MariaDB SQL Server 預設帳號及密碼
root / changeme

進行密碼更改及安全性上設定
/usr/bin/mysql_secure_installation

解決 ArchLinux 套件更新時出現的錯誤

做套件更新時出現錯誤
# pacman -Syu
(28/28) checking for file conflicts                       [##############################] 100%
error: failed to commit transaction (conflicting files)
/sbin/ exists in both ‘bash’ and ‘filesystem’
/lib/ exists in both ‘libldap’ and ‘filesystem’
/lib/ exists in both ‘krb5’ and ‘filesystem’[@more@]

在網路上搜尋了一下,找到了下面這一篇:
arch linux – Pacman -Syu fails `/bin exists in filesystem` – Unix & Linux Stack Exchange

先不更新 filesystem 及 bash 套件
# pacman -Syu –ignore filesystem,bash

更新 bash 套件
# pacman -S bash
resolving dependencies…
looking for inter-conflicts…

Packages (1): bash-4.3.030-1

Total Installed Size:   6.38 MiB
Net Upgrade Size:       0.00 MiB

:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring                            [##############################] 100%
(1/1) checking package integrity                          [##############################] 100%
(1/1) loading package files                               [##############################] 100%
(1/1) checking for file conflicts                         [##############################] 100%
(1/1) checking available disk space                       [##############################] 100%
(1/1) upgrading bash                                      [##############################] 100%
warning: directory permissions differ on /etc/
filesystem: 775  package: 755

似乎是 /etc 目錄權限有問題,不能更新

檢查 /etc 目錄權限,目錄權限為 775
# ls -ld /etc
drwxrwxr-x 61 1001 1001 4096 Oct 31 11:04 /etc

更改 /etc 目錄權限為 755
# chmod 755 /etc

/etc 目錄權限已更改為 755
# ls -ld /etc
drwxr-xr-x 61 1001 1001 4096 Oct 31 11:04 /etc

再更新一次 bash,就能正常更新了
# pacman -S bash
warning: bash-4.3.030-1 is up to date — reinstalling
resolving dependencies…
looking for inter-conflicts…

Packages (1): bash-4.3.030-1

Total Installed Size:   6.38 MiB
Net Upgrade Size:       0.00 MiB

:: Proceed with installation? [Y/n] y
(1/1) checking keys in keyring                            [##############################] 100%
(1/1) checking package integrity                          [##############################] 100%
(1/1) loading package files                               [##############################] 100%
(1/1) checking for file conflicts                         [##############################] 100%
(1/1) checking available disk space                       [##############################] 100%
(1/1) reinstalling bash                                   [##############################] 100%

更新剩下的 filesystem
# pacman -Su

Raspberry Pi 測試 – ArchLinux Server 篇 超頻 Overclock

參考網站:
Cortex-A/M: Raspberry Pi: Overclocking on Arch linux
Raspberry Pi Safe Overclocking – Hayden James
修改 /boot/config.txt
# vim /boot/config.txt
##None(未超頻)
#arm_freq=700
#core_freq=250
#sdram_freq=400
#over_voltage=0

##Modest(超頻一些)
#arm_freq=800
#core_freq=300
#sdram_freq=400
#over_voltage=0

##Medium(中等)
#arm_freq=900
#core_freq=333
#sdram_freq=450
#over_voltage=2

##High(快)
#arm_freq=950
#core_freq=450
#sdram_freq=450
#over_voltage=6

##Turbo(最快)
#arm_freq=1000
#core_freq=500
#sdram_freq=500
#over_voltage=6[@more@]

這裡改用 Turbo
##Turbo
arm_freq=1000
core_freq=500
sdram_freq=500
over_voltage=6

重新啟動電腦
# reboot

Raspberry Pi 測試 – ArchLinux Server 篇 擴展 root 分割區

參考網站:Cubiksoundz – Technically Speaking…: Expanding Raspberry Pi SD Card Partition on Arch Linux
分割硬碟
# fdisk /dev/mmcblk0

[@more@]刪除第 2 個分割區
Command (m for help): d
Partition number (1,2,5, default 5): 2

Partition 2 has been deleted.

建立 extended 分割區
Command (m for help): n

Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e
Partition number (2-4, default 2): 2
First sector (186368-30881791, default 186368):
Last sector, +sectors or +size{K,M,G,T,P} (186368-30881791, default 30881791):

Created a new partition 2 of type ‘Extended’ and of size 14.7 GiB.

建立 logical 分割區
Command (m for help): n

Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 5
First sector (188416-30881791, default 188416):
Last sector, +sectors or +size{K,M,G,T,P} (188416-30881791, default 30881791):

Created a new partition 5 of type ‘Linux’ and of size 14.7 GiB.

寫入並結束

重新啟動電腦
# reboot

使用 resize2fs 擴大分割區的大小
# resize2fs /dev/mmcblk0p5
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mmcblk0p5 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p5 is now 3836672 blocks long.

pacman 指令

pacman 是 ArchLinux 用來管理套件的工具,相當於 RedHat / CentOS 的 yum / rpm 及 Debian / Ubuntu 的 apt-* / dpkg。
參考網站:pacman (正體中文) – ArchWiki
更新套件庫
# pacman -Syy
Debian / Ubuntu
# apt-get update
RedHat / CentOS
# yum update

更新已安裝的套件
# pacman -Syu
# pacman -S –refresh –sysupgrade
# pacman -S -y -u
Debian / Ubuntu
# apt-get upgrade
# apt-get dist-upgrade
RedHat / CentOS
# yum update[@more@]

尋找套件
# pacman -Ss ncftp
# pacman -S –search ncftp
extra/ncftp 3.2.5-4
    A set of free application programs implementing FTP
Debian / Ubuntu
# apt-cache search ncftp
RedHat / CentOS
# yum search ncftp

安裝套件
# pacman -S 套件名稱
Debian / Ubuntu
# apt-get install 套件名稱
# dpkg -i 套件檔案名稱
RedHat / CentOS
# yum install 套件名稱
# rpm -ivh 套件檔案名稱

查看套件群組包含的套件
# pacman -Sg gnome
# pacman -S –group gnome
gnome baobab
gnome empathy
gnome eog
gnome epiphany
gnome evince
gnome gdm
gnome gnome-backgrounds
gnome gnome-calculator
gnome gnome-contacts
gnome gnome-control-center
gnome gnome-desktop
gnome gnome-dictionary
gnome gnome-disk-utility
gnome gnome-font-viewer
gnome gnome-icon-theme
gnome gnome-icon-theme-extras
gnome gnome-icon-theme-symbolic
gnome gnome-keyring
gnome gnome-screenshot
gnome gnome-session
gnome gnome-settings-daemon
gnome gnome-shell
gnome gnome-shell-extensions
gnome gnome-system-log
gnome gnome-system-monitor
gnome gnome-terminal
gnome gnome-themes-standard
gnome gnome-user-docs
gnome gnome-user-share
gnome grilo-plugins
gnome gucharmap
gnome mousetweaks
gnome mutter
gnome nautilus
gnome sushi
gnome totem
gnome tracker
gnome vino
gnome xdg-user-dirs-gtk
gnome yelp
RedHat / CentOS
# yum groupinfo “PHP Support”
Loaded plugins: downloadonly, fastestmirror
Setting up Group Process
Loading mirror speeds from cached hostfile

Group: PHP Support
 Description: PHP web application framework.
 Mandatory Packages:
   php
 Default Packages:
   php-gd
   php-pdo
   php-pear
   php-xml
 Optional Packages:
   php-ldap
   php-mysql
   php-odbc
   php-pecl-apc
   php-pecl-memcache
   php-pgsql
   php-soap
   php-xmlrpc

移除套件
# pacman -Rc
# pacman -R –cascade   remove packages and all packages that depend on them
# pacman -Rd
# pacman -R –nodeps  skip dependency version checks (-dd to skip all checks)
# pacman -Ru
# pacman -R –unneeded  remove unneeded packages

# pacman -R 套件名稱
Debian / Ubuntu
# apt-get remove 套件名稱
# dpkg -r 套件名稱
RedHat / CentOS
# yum remove 套件名稱
# rpm -e 套件名稱

移除套件及其相依性套件
# pacman -R –recursive 套件名稱
# pacman -Rs 套件名稱

移除套件但不移除相依性的套件
# pacman -Rdd 套件名稱

移除套件也一併刪除設定檔
# pacman -Rn 套件名稱
# pacman -R –nosave 套件名稱
Debian / Ubuntu
# apt-get remove –purge 套件名稱
# dpkg -P 套件名稱

查詢已安裝的套件資訊
# pacman -Q –info dnsutils
# pacman -Qi dnsutils
Name           : dnsutils
Version        : 9.9.2.P2-2
Description    : DNS utilities: dig host nslookup
Architecture   : armv6h
URL            : http://www.isc.org/software/bind/
Licenses       : custom:ISC
Groups         : None
Provides       : None
Depends On     : openssl  krb5  idnkit  dnssec-anchors
Optional Deps  : None
Required By    : None
Optional For   : None
Conflicts With : None
Replaces       : bind-tools  host
Installed Size : 1857.00 KiB
Packager       : Arch Linux ARM Build System <builder+xu4@archlinuxarm.org>
Build Date     : Wed Jul 2 11:59:28 2014
Install Date   : Mon Sep 29 00:11:31 2014
Install Reason : Explicitly installed
Install Script : No
Validated By   : SHA256 Sum
RedHat / CentOS
# rpm -qi 套件名稱

套件安裝位置
# pacman -Q –list dnsutils
# pacman -Ql dnsutils
dnsutils /usr/
dnsutils /usr/bin/
dnsutils /usr/bin/dig
dnsutils /usr/bin/host
dnsutils /usr/bin/nslookup
dnsutils /usr/share/
dnsutils /usr/share/licenses/
dnsutils /usr/share/licenses/dnsutils/
dnsutils /usr/share/licenses/dnsutils/LICENSE
dnsutils /usr/share/man/
dnsutils /usr/share/man/man1/
dnsutils /usr/share/man/man1/dig.1.gz
dnsutils /usr/share/man/man1/host.1.gz
dnsutils /usr/share/man/man1/nslookup.1.gz
Debian / Ubuntu
# dpkg -L 套件名稱
RedHat / CentOS
# rpm -ql 套件名稱
# repoquery –verbose -l 套件名稱

列出系統中已安裝的套件
# pacman -Q –search
# pacman -Qs
# pacman -Qs | grep local | awk -F’/’ ‘{print $2}’
Debian / Ubuntu
# dpkg -l
# dpkg -l | grep ^ii | awk ‘{print $2}’
RedHat / CentOS
# rpm -qa

查詢系統有無安裝特定的套件
# pacman -Qs vim
# pacman -Qs vim | grep local | awk -F’/’ ‘{print $2}’
vim 7.4.473-1
vim-runtime 7.4.473-1
# pacman -Qs vim | grep local | awk -F’/’ ‘{print $2}’ | awk ‘{print $1}’
vim
vim-runtime
Debian / Ubuntu
# dpkg -l | grep vim
RedHat / CentOS
# rpm -qa | grep vim

查詢未安裝的套件資訊
# pacman -Si ncftp
Repository     : extra
Name           : ncftp
Version        : 3.2.5-4
Description    : A set of free application programs implementing FTP
Architecture   : armv6h
URL            : http://www.ncftp.com/
Licenses       : custom
Groups         : None
Provides       : None
Depends On     : ncurses
Optional Deps  : None
Conflicts With : None
Replaces       : None
Download Size  : 198.77 KiB
Installed Size : 997.00 KiB
Packager       : Arch Linux ARM Build System <builder+xu4@archlinuxarm.org>
Build Date     : Fri Mar 7 21:14:08 2014
Validated By   : MD5 Sum  SHA256 Sum  Signature
RedHat / CentOS
# rpm -qpi ncftp

查詢檔案是屬於哪一個套件
# pacman -Q –owns /etc/vimrc
# pacman -Qo /etc/vimrc
/etc/vimrc is owned by vim-runtime 7.4.459-1
RedHat / CentOS
# rpm -qf /etc/vimrc
Debian / Ubuntu
# dpkg-query -S /etc/vimrc

列出系統中用不到的套件
# pacman -Qdt
libgssglue 0.4-2

移除安裝或更新套件時下載的安裝檔
清除 /var/lib/pacman/var/cache/pacman/pkg 目錄
# pacman -Scc

Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove ALL files from cache? [y/N] y
removing all files from cache…

Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n] y
removing unused sync repositories…
Debian / Ubuntu
# apt-get clean all
# apt-get autoclean
RedHat / CentOS
# yum clean all

pacman 版本資訊
# pacman -V

 .–.                  Pacman v4.1.2 – libalpm v8.0.2
/ _.-‘ .-.  .-.  .-.   Copyright (C) 2006-2013 Pacman Development Team
  ‘-. ‘-‘  ‘-‘  ‘-‘   Copyright (C) 2002-2006 Judd Vinet
 ‘–‘
                       This program may be freely redistributed under
                       the terms of the GNU General Public License.