『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 用户名



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