『Linux學習』基本命令篇(六)

1.網絡管理:

1)/etc/hosts

[root@localhost ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       localhost.localdomain   localhost

2)/etc/sysconfig/network

系統設置的配置文件:

[root@localhost ~]# ls -l /etc/sysconfig/
total 592
-rw-r--r--  1 root root   56 Oct  7  2006 amd
-rw-r--r--  1 root root 4765 Oct  7  2006 apmd
drwxr-xr-x  2 root root 4096 Oct 16 07:40 apm-scripts
-rw-r--r--  1 root root  201 Oct  8  2006 arpwatch
-rw-r-----  1 root root  514 Oct  7  2006 auditd
-rw-r--r--  1 root root  194 Oct 16 08:23 authconfig
-rw-r--r--  1 root root  824 Oct  7  2006 autofs
-rw-r--r--  1 root root  232 Oct  7  2006 bluetooth
-rw-r--r--  1 root root   41 Oct 16 08:52 clock
drwxr-xr-x  2 root root 4096 Oct 23  2006 console
-rw-r--r--  1 root root  512 Oct  8  2006 crond
-rw-r--r--  1 root root  109 Oct  7  2006 cyrus-imapd
-rw-r--r--  1 root root   16 Oct 16 08:23 desktop
-rw-r--r--  1 root root   91 Oct  7  2006 dhcp6r
-rw-r--r--  1 root root   85 Oct  7  2006 dhcp6s
-rw-r--r--  1 root root   39 Oct  7  2006 dhcpd
-rw-r--r--  1 root root   57 Oct  7  2006 dhcrelay
-rw-r--r--  1 root root 3173 Oct  7  2006 diskdump
-rw-r--r--  1 root root   31 Oct  7  2006 dund
-rw-r--r--  1 root root   20 Oct  7  2006 exim
-rw-r--r--  1 root root   17 Oct 16 08:52 firstboot
-rw-r--r--  1 root root   25 Oct 16 08:23 grub
-rw-r--r--  1 root root 1592 Oct  7  2006 harddisks
-rw-r--r--  1 root root   30 Oct  7  2006 hidd
-rw-r--r--  1 root root  616 Oct 23  2006 httpd
-rw-r--r--  1 root root 3021 Nov 17 00:28 hwconf
-rw-r--r--  1 root root  101 Oct 16 08:23 i18n
-rw-r--r--  1 root root  991 May 20  2003 init
-rw-r--r--  1 root root   74 Oct 16 08:23 installinfo
-rw-------  1 root root 1386 Oct  7  2006 ip6tables-config
-rw-r--r--  1 root root 2296 Oct  7  2006 ipmi
-rw-------  1 root root 1375 Oct  7  2006 iptables-config
-rw-r--r--  1 root root   58 Oct  7  2006 irda
-rw-r--r--  1 root root  358 Oct 25  2006 irqbalance
-rw-------  1 root root  430 Oct  7  2006 iscsi
-rw-r--r--  1 root root  188 Oct 16 08:23 kernel
-rw-r--r--  1 root root   32 Oct 16 08:23 keyboard
-rw-r--r--  1 root root  168 Oct  7  2006 kudzu
-rw-r--r--  1 root root  134 Oct  7  2006 lm_sensors
-rw-r--r--  1 root root  115 Oct 16 08:23 mouse
-rw-r--r--  1 root root  408 Oct 16 08:01 named
-rw-r--r--  1 root root 1940 Oct  7  2006 netdump
-rw-------  1 root root  668 Oct 16 07:40 netdump_id_dsa
-rw-r--r--  1 root root  616 Oct 16 07:40 netdump_id_dsa.pub
-rw-r--r--  1 root root   46 Nov  8 18:20 network
drwxr-xr-x  4 root root 4096 Oct 16 07:39 networking
drwxr-xr-x  2 root root 4096 Oct 16 08:22 network-scripts
-rw-r--r--  1 root root  157 Oct  7  2006 ntpd
-rw-r--r--  1 root root  349 Oct 25  2006 o2cb
-rw-r--r--  1 root root  262 Oct  7  2006 openib.conf
-rw-r--r--  1 root root  665 Oct 25  2006 oracleasm
-rw-r--r--  1 root root   71 Oct  7  2006 pand
-rw-r--r--  1 root root   38 Oct 16 08:22 pcmcia
drwxr-xr-x  2 root root 4096 Oct  7  2006 pgsql
-rw-r--r--  1 root root 1459 Oct  7  2006 prelink
-rw-r--r--  1 root root  806 Oct  8  2006 quagga
-rw-r--r--  1 root root  249 Oct  8  2006 radvd
-rw-r--r--  1 root root  287 Oct 19  2004 rawdevices
drwxr-xr-x  3 root root 4096 Oct 16 07:45 rhn
-rw-r--r--  1 root root  111 Oct  8  2006 samba
-rw-r--r--  1 root root  420 Oct  7  2006 saslauthd
lrwxrwxrwx  1 root root   19 Oct 16 07:39 selinux -> /etc/selinux/config
-rw-r--r--  1 root root   20 Oct  8  2006 sendmail
-rw-r--r--  1 root root   47 Oct  8  2006 spamassassin
-rw-r--r--  1 root root  297 Oct  8  2006 squid
-rw-r--r--  1 root root  454 Oct  8  2006 syslog
-rw-r--r--  1 root root   66 Oct  8  2006 sysstat
-rw-r--r--  1 root root   65 Oct 16 08:23 system-config-securitylevel
-rw-r--r--  1 root root  146 Oct 25  2006 system-config-users
-rw-r--r--  1 root root  994 Oct 25  2006 system-logviewer
-rw-r--r--  1 root root 1750 Oct 19  2006 tux
-rw-r--r--  1 root root  495 Oct  8  2006 vncservers
-rw-r--r--  1 root root  376 Oct  8  2006 xinetd
-rw-r--r--  1 root root  543 Oct  8  2006 yppasswdd

[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain

3)/etc/sysconfig/network-scripts/ifcfg/eth0

[root@localhost ~]# ls -l /etc/sysconfig/network-scripts/
total 324
-rw-r--r--  3 root root   154 Nov  8 18:20 ifcfg-eth0
-rw-r--r--  1 root root   254 Jun 21  2001 ifcfg-lo
lrwxrwxrwx  1 root root    20 Oct 16 07:39 ifdown -> ../../../sbin/ifdown
-rwxr-xr-x  1 root root  1060 Jun 21  2005 ifdown-aliases
-rwxr-xr-x  1 root root   820 Dec  2  2003 ifdown-ippp
-rwxr-xr-x  1 root root  1769 Mar 29  2005 ifdown-ipsec
-rwxr-xr-x  1 root root  4352 Sep 10  2004 ifdown-ipv6
lrwxrwxrwx  1 root root    11 Oct 16 07:39 ifdown-isdn -> ifdown-ippp
-rwxr-xr-x  1 root root  1133 Aug  4  2004 ifdown-post
-rwxr-xr-x  1 root root  1082 Sep 15  2003 ifdown-ppp
-rwxr-xr-x  1 root root  1568 Nov 12  2002 ifdown-sit
-rwxr-xr-x  1 root root   902 Jun 26  2002 ifdown-sl
lrwxrwxrwx  1 root root    18 Oct 16 07:39 ifup -> ../../../sbin/ifup
-rwxr-xr-x  1 root root 12872 Jun  8  2004 ifup-aliases
-rwxr-xr-x  1 root root  4309 Dec  1  2005 ifup-ib
-rwxr-xr-x  1 root root 11466 Aug 19  2004 ifup-ippp
-rwxr-xr-x  1 root root  7868 Mar 29  2005 ifup-ipsec
-rwxr-xr-x  1 root root 10466 Oct 17  2004 ifup-ipv6
-rwxr-xr-x  1 root root   821 Jun 26  2002 ifup-ipx
lrwxrwxrwx  1 root root     9 Oct 16 07:39 ifup-isdn -> ifup-ippp
-rwxr-xr-x  1 root root   689 Jun 26  2002 ifup-plip
-rwxr-xr-x  1 root root   926 Jun 26  2002 ifup-plusb
-rwxr-xr-x  1 root root  2800 Aug 21  2004 ifup-post
-rwxr-xr-x  1 root root  3926 Oct 23  2003 ifup-ppp
-rwxr-xr-x  1 root root  1299 Apr 18  2005 ifup-routes
-rwxr-xr-x  1 root root  3546 Oct 17  2004 ifup-sit
-rwxr-xr-x  1 root root  1646 Jun 26  2002 ifup-sl
-rwxr-xr-x  1 root root  3171 Oct 11  2004 ifup-wireless
-rwxr-xr-x  1 root root  5408 Aug 18  2003 init.ipv6-global
-rw-r--r--  1 root root  9596 Jun 10  2005 network-functions
-rw-r--r--  1 root root 42087 Dec  9  2004 network-functions-ipv6

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
HWADDR=08:00:27:09:6C:CA
ONBOOT=yes
TYPE=Ethernet
NETMASK=255.255.255.0
IPADDR=192.168.56.2
USERCTL=no
PEERDNS=yes
IPV6INIT=no

2.Linux操作系統怎樣識別設備

1)oracle linux是以模塊的方式載入網卡驅動程序的,如果已經設置在開機就使用網絡,那麼系統在開機啓動時就會自動載入驅動程序模塊。

在開機時,Linux會讀取/etc/modprobe.conf文件中設定的。

所有網絡設備都使用網卡的邏輯名來引用網卡。

好處就是:當系統更換了一個網卡,就不必變更所有相關的系統配置文件和腳本中的網卡名。

[root@localhost ~]# cat /etc/modprobe.conf
alias scsi_hostadapter ahci
alias eth0 e1000
alias snd-card-0 snd-intel8x0
options snd-card-0 index=0
install snd-intel8x0 /sbin/modprobe --ignore-install snd-intel8x0 && /usr/sbin/alsactl restore >/dev/null 2>&1 || :
remove snd-intel8x0 { /usr/sbin/alsactl store >/dev/null 2>&1 || : ; }; /sbin/modprobe -r --ignore-remove snd-intel8x0
alias usb-controller ohci-hcd

  • ethernet以太網卡:是一eth爲首後跟一個數字編號作爲邏輯名,如:eth0,eth11等
  • Token Ring(令牌環網)卡:是使用tr爲首字母后跟一個數字。
  • FDDI(光纖網絡)卡:使用fddi爲首
  • PPP(撥號網卡):ppp爲首
使用ifconfig或dmesg查看網卡的編號。

[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:09:6C:CA
          inet addr:192.168.56.2  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe09:6cca/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:720 errors:0 dropped:0 overruns:0 frame:0
          TX packets:388 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:58098 (56.7 KiB)  TX bytes:35193 (34.3 KiB)
          Base address:0xd010 Memory:f0000000-f0020000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1908 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1908 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2369424 (2.2 MiB)  TX bytes:2369424 (2.2 MiB)

3.ifconfig
[root@localhost ~]# ifconfig eth0 192.168.177.6 netmask 255.255.255.0 broadcast 192.168.177.254

使用ifdown和ifup啓動和停止網卡。

4.netconfig配置網絡

[root@localhost ~]# netconfig

4.在一個網卡上綁定多個ip地址:
如果要在一個網卡上綁定少量的IP地址,可以手動的爲每個IP地址創建一個網絡配置文件,這些網絡配置文件的文件名必須以
ifcfg-
開頭
,後跟網卡的邏輯名,之後是冒號緊跟數字表示是第幾個虛擬網卡。
配置文件的格式是:
ifcfg-ethN:nnn

N是自然數,表示第幾個網卡
nnn表示這個網卡配置第幾個虛擬網卡。

ifcfg-eth0:0表示第一個虛擬網卡,可以綁定一個IP。

綁定大量的IP:
ifcfg-ehN-rangeN
在這個文件中設置ip的範圍:

都是這個路徑下配置。
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
5.一些用戶管理命令:
[root@localhost ~]# finger zhao
Login: zhao                             Name: zhao
Directory: /home/zhao                   Shell: /bin/bash
On since Sat Nov 17 09:57 (CST) on pts/1 from 192.168.56.1
No mail.
No Plan.

newusers命令可以加入多個用戶。

羣組:
groupadd
groupmod
groupdel

usermod [  選項 ] 用戶名

可以通過/etc/login.defs文件中的設置來修改默認密碼的有限期限。

change命令修改用戶的密碼期限

change [  選項  ]  用戶名

6.RAID磁盤列陣:
1.
[root@localhost ~]# mdadm -C /dev/md0 -l 1 -n 2 /dev/sdb1 /dev/sdc1

-C表示要創建一個RAID磁盤陣列。

-l選項指明RAID磁盤陣列的level

-n是要指明分區的數量。

7.創建邏輯卷:

[root@localhost ~]# pvcreate /dev/sde1 //轉換成一個物理卷
[root@localhost ~]# pvcreate /dev/sdf1  //轉換成物理卷
[root@localhost ~]# vgcreate vgd /dev/sde1 /dev/sdf1 //創建一個邏輯卷
[root@localhost ~]# lvcreate -L 250M -n lvdog vgd //分配一個150M的邏輯卷
[root@localhost ~]# ls -l /dev/vgd //如果顯示結果有 /dev/mapper/vgd-lvdog,說明成功
[root@localhost ~]# mke2fs -j /dev/vgd/lvdog//格式化
[root@localhost ~]# lvextend -L 250M /dev/vgd/lvdog//擴展邏輯卷
[root@localhost ~]# ext2online /dev/vgd/lvdog//聯機方式格式化
[root@localhost ~]# pvcreate /dev/sdg1
[root@localhost ~]# vgextend vgd /dev/sdg1 //擴展邏輯卷
[root@localhost ~]# lvremove /dev/vgd/lvdog//移除
[root@localhost ~]# vgdisplay
[root@localhost ~]# pvremove /dev/sde1 /dev/sdf1 /dev/sdg1//移除物理卷

8.磁盤配額:
[root@localhost ~]# quotacheck -c /home

quota 用戶

quotaon

quotacheck 

edquota 用戶名



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章