一、添加用戶useradd命令
例子:
#useradd –m –g users –G wheel,sales –s /bin/tcsh –c “a user” myname
#useradd -c "ftp Administrator" -d /var/ftp/ -G ftpAdmin -s /sbin/nologin -r ftpAdmin
-m 自動創建用戶的主目錄,並把框架目錄(/etc/skel)文件複製到用戶目錄上。
-g 設置基本組,用戶將在該組中。
-G 把用戶加到所有逗號間隔的分組中。
-s 制定使用的shell。
-c 描述信息。
-d 爲賬號設置主目錄。
-r 系統帳號,無需再/home下創建主目錄。
最後的是用戶名
二、指定口令(密碼)passwd
例子: #passwd 用戶名
回車就會提示輸入密碼了。
三、刪除用戶userdel
例子:#userdel 用戶名
#userdel –r 用戶名
-r 刪除其主目錄(/home/…..)
四、 文件系統命令
4.1 fdisk命令
(1)fdisk –l :顯示硬盤上的所有分區。既分區類型(FAT32、Ext3)。
(2)df –h :顯示文件系統是如何掛載的。
(3)fdisk /dev/hdb1 :格式化第二個IDE磁盤
4.2 mount命令掛載文件系統
(1)mount (不使用參數)查看系統掛載情況。
(2)mount /mnt/cdrom :掛載光驅,可用cd /mnt/cdrom 後ls查看光盤上的內容。
(3)mount /mnt/floppy :掛載軟盤,可用cd /mnt/floppy 後ls查看軟盤上的內容。
2、3中可以使用/dev/cdrom和/dev/fd0代替掛載點,得到同樣的效果!
(4)mount –t msdos /dev/fd0 /mnt/floppy :掛載DOS軟盤到/mnt/floppy下。
(5)掛載Windows分區
#fdisk -l :列出硬盤分區。
#mkdir /mnt/win :創建一個目錄,用於掛載。
#mount -t vfat /dev/hda1 /mnt/win :假設Windows在第一個IDE硬盤的第一
注:可以使用–t auto 參數令系統自動監測文件類型!
-r 以只讀方式掛載。
-w 讀寫方式掛載。
4.3 umount命令卸載文件系統
(1) umount /mnt/floppy 將設備(如/dev/fd0)從掛載點/mnt/floppy卸載。也可以使用下列方式
爲了使該分區對於Linux永久可用,需在/etc/fstab文件中添加如下一行:
/dev/hda1 /mnt/win vfat defaults 0 0
五、 文件相關命令
5.1 文件權限chmod
例子:
chmod 777 files -〉rwxrwxrwx
chmod 755 files -〉rwx r-x r-x
chmod 644 files -〉rw- -r- -r-
chmod 000 files -〉- - - - - - - - -
chmod u+x g+w o+r file(給file以擁有者可執行、同組可寫、其他人可讀取的權利)
$ chmod –R 777 /tmp/test :更改目錄中所有文件和目錄的權限(所有權限)。
$ chmod –R 664 /tmp/test :關閉執行權限。
5.2 文件所有權
chown user1 file(把file分配給user1)
5.3 移動文件mv
例子: mv abc def 本文件abc移動更名爲def。
六、 iptables命令面面觀
外網:eth0 123.45.67.89
內網:eth1 10.0.0.1 LAN上的計算機IP地址都在10.0.0.2~~10.0.0.254之間。
(1)一個rc.local的例子,在rc.local中加入如下命令
echo 1 > /proc/sys/net/ipv4/ip_forward #啓動IP轉發
echo 1 > /proc/sys/net/ipv4/ip_dynaddr #啓動動態IP地址
#Policies(Default)設置默認策略爲拒絕
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
#User-defined chain for ACCEPTed TCP packets用戶自定義鏈,鏈名爲“okay”
iptables -N okay
iptables -A okay –p TCP - - syn –j ACCEPT
iptables -A okay –p TCP -m state - -state ESTABLISHED,RELATED –j ACCEPT
iptables -A okay –p TCP –j DROP
#INPUT chain rules
# Rules for incoming packets from LAN
iptables -A INPUT -p ALL -i eth1 -s 10.0.0.0/8 -j ACCEPT #LAN中的地址可接受
iptables -A INPUT -p ALL -i lo -s 127.0.0.1 -j ACCEPT #允許接受本身的數據包
iptables -A INPUT -p ALL -i lo -s 10.0.0.1 -j ACCEPT #允許接受本身的數據包
iptables -A INPUT -p ALL -i lo -s 123.45.67.89 -j ACCEPT #允許接受本身的數據包
iptables -A INPUT -p ALL -i eth1 –d 10.0.0.255 -j ACCEPT #允許接受LAN內的廣播包
# Rules for incoming packets from the Internet
# packets for established connections
iptables -A INPUT -p ALL -d 123.45.67.89 -m state –state ESTABLISHED,RELATED –j
# TCP rules 由okay鏈處理
iptables -A INPUT -p TCP -i eth0 -s 0/0 --destination-port 21 –j okay
iptables -A INPUT -p TCP -i eth0 -s 0/0 --destination-port 22 –j okay
iptables -A INPUT -p TCP -i eth0 -s 0/0 --destination-port 80 –j okay
iptables -A INPUT -p TCP -i eth0 -s 0/0 --destination-port 113 –j okay
# UDP rules 定義開放的UDP端口
iptables -A INPUT -p UDP -i eth0 -s 0/0 --destination-port 53 –j ACCEPT
iptables -A INPUT -p UDP -i eth0 -s 0/0 --destination-port 2074 –j ACCEPT
iptables -A INPUT -p UDP -i eth0 -s 0/0 --destination-port 4000 –j ACCEPT
# ICMP rules
iptables -A INPUT -p ICMP -i eth0 -s 0/0 --destination-port 8 –j ACCEPT
iptables -A INPUT -p ICMP -i eth0 -s 0/0 --destination-port 11 –j ACCEPT
# FORWARD chain rules
#Accept the packets we want to forward
iptables -A FORWARD -i eth1 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
# OUTPUT chain rules
# Only output packets with local addresses (no spoofing)
iptables -A OUTPUT -p ALL -s 127.0.0.1 -j ACCEPT
iptables -A OUTPUT -p ALL -s 10.0.0.1 -j ACCEPT
iptables -A OUTPUT -p ALL -s 123.45.67.89 -j ACCEPT
# POSTROUTING chain rules 網關的IP僞裝
iptables -t nat –A POSTROUTING –o eth0 –j SNAT –to-source 123.45.67.89
(2)網關的IP僞裝:靜態地址 使用SNAT,動態地址(撥號) 使用MASQUERADE
例子:
MASQUERADE必須提供接口名(eth0,ppp0等)來指明路徑,好像靜態地址也可以使用MASQUERADE:
iptables -t nat -A POSTROUTING –o eth0 –j MASQUERADE
SNAT也必須指明實際的IP如下所示:
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 12.12.12.12
(3)端口轉發
例子:將對防火牆計算機(-d 15.15.15.15)的所有Web服務重定向到LAN上的某臺計算機(10.0.0.25)
iptables -t nat -A PREROUTING -p tcp -d 15.15.15.15 –dprot 80 –j DNAT –
七、IP地址類型(第一部分數字的範圍)
A類地址:0~127;可容納計算機數量爲 256*256*256。子網掩碼255.0.0.0。
B類地址:128~191;可容納計算機數量爲 256*256。子網掩碼255.255.0.0。
C類地址:192~233;可容納計算機數量爲 250個。子網掩碼255.255.255.0。
0和255不能被指定爲主機地址。
C類私有IP地址 192.168.0.0~192.168.255.255
八、ifconfig
ifconfig :判斷網絡連接情況。
ifconfig eth0 up :啓動eth0接口。
九、配置網卡
配置文件 /etc/sysconfig/network-scripts/ifcfg-eth0用vi編輯即可。例子如下
DEVICE=eth0 #設備名,與文件同名。
ONBOOT=yes #在系統啓動時,啓動本設備。
BOOTPROTO=static
IPADDR=202.118.75.91 #此網卡的IP地址
NETMASK=255.255.255.0 #子網掩碼
GATEWAY=202.118.75.1 #網關IP
MACADDR=00:02:2D:2E:8C:A8 #mac地址
十、FTP服務
10.1 使用setup命令開啓vsftpd服務進程。
10.2然後修改文件/etc/xinetd.d/vsftpd。(但vsftpd是依附於xinetd.d運行時2、3有效)
(1)把disable=yes改爲=no。