ifconfig详解

来源:互联网 发布:索尼x8500b安装软件 编辑:程序博客网 时间:2024/06/16 03:55
  •  ifconfig命令作用

ifconfig 是一个用来查看、配置、启用或禁用网络接口的工具,这个工具极为常用的。可以用这个工具来临时性的配置网卡的IP地址、掩码、广播地址、网关等。也可以把它写入一个文件中(比如/etc/rc.d/rc.local),这样系统引导后,会读取这个文件,为网卡设置IP地址

 ifconfig命令作用

1.ifconfig 查看网络接口状态 

  1. hostname%ifconfig -a 
  2. lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 
  3.         inet 127.0.0.1 netmask ff000000  
  4. e1000g0: flags=1000863<UP,BROADCAST,NOTRAILERS,RUNNING,MULTICAST,IPv4> mtu 1500 index 7 
  5.         inet 10.142.35.7 netmask ffffffc0 broadcast 10.142.35.63 
  6. e1000g0:1: flags=1000863<UP,BROADCAST,NOTRAILERS,RUNNING,MULTICAST,IPv4> mtu 1500 index 7 
  7.         inet 10.142.35.10 netmask ffffffc0 broadcast 10.142.35.63 
  8. cip0: flags=1008843<UP,BROADCAST,RUNNING,MULTICAST,PRIVATE,IPv4> mtu 1500 index 8 
  9.         inet 192.168.127.1 netmask ffffff00 broadcast 192.168.127.255 
  10.         ether 0:21:28:82:ae:ce  
  11. hostname%  



说明:
e1000g0 表示第一块网卡,速率1000bps 其中 HWaddr 表示网卡的物理地址,可以看到目前这个网卡的物理地址(MAC地址)是 00:03:0D:27:86:41; inet addr 用来表示网卡的IP地址,此网卡的 IP地址是 192.168.1.86,广播地址, Bcast:192.168.1.255,掩码地址Mask:255.255.255.0

lo 是表示主机的回坏地址,这个一般是用来测试一个网络程序,但又不想让局域网或外网的用户能够查看,只能在此台主机上运行和查看所用的网络接口。比如把 HTTPD服务器的指定到回坏地址,在浏览器输入 127.0.0.1 就能看到你所架WEB网站了。但只是您能看得到,局域网的其它主机或用户无从知道;

如果想知道主机所有网络接口的情况,请用下面的命令;
ifconfig -a
ifconfig eth0

2.ifconfig 配置网络接口 

ifconfig 网络端口 IP地址 hw MAC地址 netmask 掩码地址 broadcast 广播地址 [up/down]

示例1:配置网卡ip(零时生效,网卡/系统重启后失效)

ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0

示例2:配置物理网卡

ifconfig eth1 192.168.1.252 hw ether 04:64:03:00:12:51 netmask 255.255.255.0 broadcast 192.168.1.255 up

3.用ifconfig 来配置虚拟网络接口 

有时我们为了满足不同的需要还需要配置虚拟网络接口,比如我们用不同的IP地址来架运行多个HTTPD服务器,就要用到虚拟地址;这样就省却了同一个IP地址,如果开设两个的HTTPD服务器时,要指定端口号。

虚拟网络接口指的是为一个网络接口指定多个IP地址,虚拟接口是这样的 eth0:0 、 eth0:1、eth0:2 ... .. eth1N。当然您为eth1 指定多个IP地址,也就是 eth1:0、eth1:1、eth1:2 ... ...以此类推;

其实用ifconfig 为一个网卡配置多个IP地址,就用前面我们所说的ifconfig的用法,这个比较简单;看下面的例子;
[root@linuxchao ~]#ifconfig eth1:0 192.168.1.251 hw ether 04:64:03:00:12:51 netmask 255.255.255.0 broadcast 192.168.1.255 up

[root@linuxchao ~]#ifconfig eth1 hw ether 04:64:03:00:12:51
[root@linuxchao ~]#ifconfig eth1 192.168.1.251 netmask 255.255.255.0 broadcast 192.168.1.255 up

注意:指定时,要为每个虚拟网卡指定不同的物理地址;

在 Redhat/Fedora 或与Redhat/Fedora类似的系统,您可以把配置网络IP地址、广播地址、掩码地址、物理地址以及激活网络接口同时放在一个句子中,写入/etc/rc.d/rc.local中。比如下面的例子;
ifconfig eth1:0 192.168.1.250 hw ether 00:11:00:33:11:44 netmask 255.255.255.0 broadcast 192.168.1.255 up
ifconfig eth1:1 192.168.1.249 hw ether 00:11:00:33:11:55 netmask 255.255.255.0 broadcast 192.168.1.255 up

解说:上面是为eth1的网络接口,设置了两个虚拟接口;每个接口都有自己的物理地址、IP地址... ...

4.用ifconfig 来激活和终止网络接口的连接 

 

svcadm disable physical

svcadm enable physical 
5.配置文件内容

  1. hostname% more /etc/inet/netmasks 
  2. # The netmasks file associates Internet Protocol (IP) address 
  3. # masks with IP network numbers. 
  4. #  
  5. #       network-number  netmask 
  6. # The term network-number refers to a number obtained from the Internet Network 
  7. # Information Center. 
  8. # Both the network-number and the netmasks are specified in 
  9. # "decimal dot" notation, e.g: 
  10. #               128.32.0.0 255.255.255.0 
  11. 192.168.12.13    255.255.255.192 
  12. hostname%  

6. 重启服务命令解释

示例如下:

 

  1. # svcadm disable svc:/network/ntp  ----停止NTP 
  2. # svcadm enable svc:/network/ntp  ----启动NTP 
  3. # svcadm restart svc:/network/ntp  ----重启NTP 
  4. # svcadm refresh svc:/network/ntp  ----刷新NTP 

 

  1. hostname% svcadm 
  2. 用法:svcadm [-v] [命令 [参数 ...]] 
  3.  
  4.         svcadm enable [-rst] <服务> ... - 启用服务并使服务联机 
  5.         svcadm disable [-st] <服务> ... - 禁用服务并使服务脱机 
  6.         svcadm restart <服务> ...               - 重新启动指定的服务 
  7.         svcadm refresh <服务> ...               - 重新读取服务配置 
  8.         svcadm mark [-It] <状态> <服务> ...     - 设置维护状态 
  9.         svcadm clear <服务> ...         - 清除维护状态 
  10.         svcadm milestone [-d] <里程碑>  - 进入服务里程碑 
  11.  
  12.         可以使用 FMRI、缩写、或 fnmatch(5) 模式指定 
  13.         服务,svc:/network/smtp:sendmail 的示例如下所示: 
  14.  
  15.         svcadm <命令> svc:/network/smtp:sendmail 
  16.         svcadm <命令> network/smtp:sendmail 
  17.         svcadm <命令> network/*mail 
  18.         svcadm <命令> network/smtp 
  19.         svcadm <命令> smtp:sendmail 
  20.         svcadm <命令> smtp 
  21.         svcadm <命令> sendmail 
  22. hostname% 

6. 其他服务命令大全

  1. 1.Disabled Volume Management 
  2. # cd /etc/rc2.d 
  3. # mv S92volmgt s92volmgt 
  4. After this configuration, CD-ROMs will not be automatically mounted. To manually mount a CD-ROM use: 
  5. # mount -F hsfs -o ro /dev/dsk/c0t6d0s0 /mnt 
  6. 2.Disabled Dtlogin 
  7. Dtlogin is disabled if the server is not intended to run the Common Desktop Environment (CDE) or GUIs. 
  8. # cd /etc/rc2.d 
  9. # mv S99dtlogin s99dtlogin 
  10. 3.Disabled Printing 
  11. # /usr/lib/lpshut 
  12. # cd /etc/rc2.d 
  13. # mv S80lp s80lp 
  14. 4.Disabled RPC 
  15. RPC is disabled if the server is not intended to run CDE. To determine what is using rcp, use “rpcinfo –p”. 
  16. # cd /etc/rc2.d 
  17. # mv /etc/rc2.d/S71rpc /etc/rc2.d/s71rpc 
  18. 5.Disabled the NFS Client 
  19. # /etc/init.d/nfs.client stop 
  20. # cd /etc/rc2.d 
  21. # mv S73nfs.client s73nfs.client 
  22. 6.Disabled the NFS Server 
  23. # /etc/init.d/nfs.server stop 
  24. # cd /etc/rc3.d 
  25. # mv S15nfs.server s15nfs.server 
  26. 7.Disabled UUCP 
  27. # cd /etc/rc2.d 
  28. # mv S70uucp s70uucp 
  29. 8.Disabled the LDAP Client 
  30. # cd /etc/rc2.d 
  31. # mv S71ldap.client s71ldap.client 
  32. 9.Disabled the Auto Mounter 
  33. # /etc/init.d/autofs stop 
  34. # cd /etc/rc2.d 
  35. # mv S74autofs s74autofs 
  36. 10.Disabled the Network Time Daemon 
  37. # /etc/init.d/xntpd stop 
  38. # cd /etc/rc2.d 
  39. # mv S74xntpd s74xntpd 
  40. 11.Disabled the Logical Link Control Driver 
  41. # cd /etc/rc2.d 
  42. # ./S40llc2 stop 
  43. # mv S40llc2 s40llc2 
  44. 12.Disabled Auto Install 
  45. # cd /etc/rc2.d 
  46. # mv S72autoinstall s72autoinstall 
  47. 13.Disabled Cachefs Daemon 
  48. # cd /etc/rc2.d 
  49. # mv S73cachefs.daemon s73cachefs.daemon 
  50. 14.Disabled Asynchronous PPP Daemon 
  51. # cd /etc/rc2.d 
  52. # mv S47pppd s47pppd 
  53. 15.Disabled cacheos.finish Script 
  54. # cd /etc/rc2.d 
  55. # mv S93cacheos.finish s93cacheos.finish 
  56. 16.Disabled Preservation of Files Killed by Vi 
  57. # cd /etc/rc2.d 
  58. # mv S80PRESERVE s80PRESERVE 
  59. 17.Disabled Power Management 
  60. # cd /etc/rc2.d 
  61. # mv S85power s85power 
  62. 18.Disabled Flash Prom Update 
  63. # cd /etc/rc2.d 
  64. # mv S75flashprom s75flashprom 
  65. Before attempting to update the eeprom, temporally enable this script. 
  66. 19.Disabled “Buttons n Dials-Setup” 
  67. # cd /etc/rc2.d 
  68. # mv S89bdconfig s89bdconfig 
  69. 20.Disabled Spc 
  70. # cd /etc/rc2.d 
  71. # mv S80spc s80spc 
  72. 21.Disabled Sun Management Center 
  73. # cd /etc/rc2.d 
  74. # mv S90wbem s90wbem 
  75. 22.Disabled Network Cache and Accelerator 
  76. # cd /etc/rc2.d 
  77. # mv S94ncalogd s94ncalogd 
  78. # mv S95ncad s95ncad 
  79. Used to increase web server performance 
  80. 23.Disabled Mobile IP Agent 
  81. # cd /etc/rc3.d 
  82. # mv S80mipagent s80mipagent 
  83. 24.Disabled SNMP 
  84. # cd /etc/rc3.d 
  85. # /usr/bin/pkill -9 -x -u 0 '(snmpdx|snmpv2d|mibiisa)' 
  86. # mv S76snmpdx s76snmpdx 
  87. 25.Disabled Apache 
  88. # cd /etc/rc3.d 
  89. # mv S50apache s50apache 
  90. 26.Disabled DMI 
  91. # cd /etc/rc3.d 
  92. # /usr/bin/pkill -9 -x -u 0 '(snmpXdmid|dmispd)' 
  93. # mv S77dmi s77dmi 
  94. 27.Disabled the Sendmail Daemon 
  95. The system continues to send mail out. It does not receive mail in to the server. This eliminates a significant security 
  96. vulnerability. 
  97. # /etc/init.d/sendmail stop 
  98. Prevented sendmail from starting at boot: 
  99. # cd /etc/rc2.d 
  100. # mv S88sendmail s88sendmail 
  101. Ensured the sendmail queue is cleaned out: 
  102. # crontab –e 
  103. # The Sendmail daemon is not running - This tells it to send mail out 
  104. 05,20,35,50 * * * * /usr/lib/sendmail –q 
  105. 28.Disabled Multicasting 
  106. Multicasting is typically used for clustering. Ensure that it is not required by an application. 
  107. # vi /etc/init.d/inetsvc 
  108. # Add a static route for multicast packets out our default interface. 
  109. # The default interface is the interface that corresponds to the node name. 
  110. #mcastif=`/sbin/dhcpinfo Yiaddr` 
  111. #if [ $? -ne 0 ]; then 
  112. mcastif=`uname -n` 
  113. #fi 
  114. #echo "Setting default interface for multicast: \c" 
  115. #/usr/sbin/route add -interface -netmask "240.0.0.0" "224.0.0.0" "$mcastif" 
  116. 29.Disabled the Serial Port Listeners 
  117. This configuration can be accomplished unless there is a modem or console terminal attached to the system. 
  118. # vi /etc/inittab 
  119. Remove the line with “/usr/lib/saf/sac -t 300” 
  120. # chown root:sys /etc/inittab 
  121. # chmod 644 /etc/inittab 
  122.  
  123. 1.Added Warning Banners 
  124. These configurations replace the operating system version with a warning banner displayed during the login process. 
  125. Login: 
  126. # vi /etc/motd (replaced operating system version with a warning banner) 
  127. Property of Company 
  128. WARNING: To protect systems from unauthorized use and to ensure that the 
  129. system is functioning properly, activities on this system are monitored and 
  130. recorded and subject to audit. Use of this system is expressed consent to such 
  131. monitoring and recording. Any unauthorized access or use of this system is 
  132. prohibited and could be subject to criminal and civil penalties. 
  133. # cp /etc/motd /etc/issue 
  134. Telnet: 
  135. # vi /etc/default/telnetd 
  136. UMASK=022 
  137. BANNER="" 
  138. # chown root:sys /etc/default/telnetd 
  139. # chmod 444 /etc/default/telnetd 
  140. FTP: 
  141. # vi /etc/default/ftpd 
  142. UMASK=022 
  143. BANNER=`cat /etc/motd` 
  144. # chown root:sys /etc/default/ftpd 
  145. # chmod 444 /etc/default/ftpd 
  146. 2.Enabled Logging of the su Command 
  147. This configuration logs both success and failure of su command usage. 
  148. NOTE: This configuration is required by the root login notification script (below). 
  149. # vi /etc/default/su 
  150. SULOG=/var/adm/sulog (uncommented) 
  151. # cd /var/adm 
  152. # touch sulog 
  153. # chgrp sys sulog 
  154. # chmod 600 sulog 
  155. 3.Enabled AUTH Logging 
  156. The auth facility controls account access with login, su, etc. 
  157. # vi /etc/syslog.conf 
  158. auth.info /var/log/authlog 
  159. auth.notice /var/log/authlog 
  160. NOTE: The entries must be separated by tabs. 
  161. # /etc/init.d/syslog stop 
  162. # /etc/init.d/syslog start 
  163. 4.Enabled Logging of Unsuccessful Login Attempts 
  164. The loginlog file records consecutive failed login attempts. 
  165. # cd /var/adm 
  166. # touch loginlog 
  167. # chgrp sys loginlog 
  168. # chmod 600 loginlog 
  169. 5.Enabled Logging of Successful Logins 
  170. # cd /var/log 
  171. # touch logins 
  172. # chgrp sys logins 
  173. # chmod 600 logins 
  174. # vi /etc/syslog.conf 
  175. # log successful logins 
  176. local0.info /var/log/logins 
  177. NOTE: The entries must be separated by tabs. 
  178. # /etc/init.d/syslog stop 
  179. # /etc/init.d/syslog start 
  180. Added the following entry to /etc/profile and /etc/.login: 
  181. logger -p local0.info "User $LOGNAME has logged in" 
  182. 6.Enabled Logging of CDE Login Attempts 
  183. # vi /etc/pam.conf 
  184. Added the word “debug” after the account management entries 
  185. # Account management 
  186. login account required /usr/lib/security/$ISA/pam_unix.so.1 debug 
  187. dtlogin account required /usr/lib/security/$ISA/pam_unix.so.1 debug 
  188. # vi /etc/syslog.conf 
  189. Added “;auth.debug;user.debug” to the line that logs successful logins 
  190. # log successful logins 
  191. local0.info;auth.debug;user.debug /var/log/logins 
  192. NOTE: The entries must be separated by tabs. 
  193. # /etc/init.d/syslog stop 
  194. # /etc/init.d/syslog start 
  195. 7.Enabled Performance Logging 
  196. # su – sys 
  197. EDITOR=vi; export EDITOR 
  198. # crontab –e 
  199. # The sys crontab should be used to do performance collection. See cron 
  200. # and performance manual pages for details on startup. 
  201. 0 * * * 0-6 /usr/lib/sa/sa1 
  202. 20,40 6-22 * * 1-5 /usr/lib/sa/sa1 
  203. 5 18 * * 1-5 /usr/lib/sa/sa2 -s 8:00 -e 18:01 -i 1200 -A 

 

 

 

本文出自 “Focus on Oracle” 博客,请务必保留此出处http://alexy.blog.51cto.com/6115453/1035777

原创粉丝点击