一.Linux网络配置文件

1.  /etc/sysconfig/network-scripts/ifcfg-eth0 文件

在Red Hat系统中,系统网络设备的配置文件保存在/etc/sysconfig/network-scripts目录下,其中文件ifcfg-eth0包含第一块网卡的配置信息,文件ifcfg-eth1包含第二块网卡的配置信息,文件ifcfg-lo包含回路IP地址信息。

[root@redhat2 ~]# ls /etc/sysconfig/network-scripts

ifcfg-eth0   ifdown-post    ifup-eth    ifup-routes

ifcfg-lo     ifdown-ppp     ifup-ippp   ifup-sit

ifdown       ifdown-routes  ifup-ipv6   ifup-tunnel

ifdown-bnep  ifdown-sit     ifup-isdn   ifup-wireless

ifdown-eth   ifdown-tunnel  ifup-plip   init.ipv6-global

ifdown-ippp  ifup           ifup-plusb  net.hotplug

ifdown-ipv6  ifup-aliases   ifup-post   network-functions

ifdown-isdn  ifup-bnep      ifup-ppp    network-functions-ipv6

[root@redhat2 ~]#

下面是/etc/sysconfig/network-scripts/ifcfg-eth0文件内容的示例。

[root@redhat2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"                           //表示物理设备的名字,如eth0,eth1

BOOTPROTO=static                //表示为网卡配置静态还是动态IP地址

IPADDR=192.168.12.11         //表示赋给该网卡的IP地址

NETMASK=255.255.255.0    //表示子网掩网

ONBOOT=yes                          //表示启动系统时是否激活该卡,yes激活,no不激活

TYPE="Ethernet"

[root@redhat2 ~]#

可以为BOOTPROTO设置4种选项。

● none:表示无需启动协议。

● bootp:表示使用bootp协议。

● dhcp: 表示使用dhcp协议动态获取IP地址。

● static:表示手工设置静态IP地址。

  1. /etc/resolv.conf文件

文件/etc/resolv.conf是由域名解析器(resolver,一个根据主机名解析IP地址的库)使用的配置文件,下面是/etc/resolv.conf文件内容的示例。

search openarch.com

nameserver 202.96.209.5

nameserver 202.96.209.6

该文件中包含的内容描述如下。

Search:表示DNS搜索路径,即解析不完整名称时默认的附件域名后缀,这样可以在解析名称时用简短的主机名而不是完全合格域名(FQDN)。

Nameserver:表示解析域名时使用该地址指定的主机为域名服务器,其中域名服务器是按照文件中出现的顺序来查询的。

  1. /etc/host.conf文件

文件/etc/host.conf指定如何解析主机名,redhat系统通过解析器库来获得主机名对应的IP地址,下面是/etc/host.conf文件内容的示例。

Order bind,hosts

Multi on

Nospoof on

该文件中包含的内容描述如下:

order bind,hosts:指定主机名查询顺序,这里规定先使用DNS来解析域名,然后再查询/etc/hosts文件。

Multi on

Nospoof on

该文件中包含的内容描述如下。

Order bind,hosts:指定主机名查询顺序,这里规定先使用DNS来解析域名,然后再查询/etc/hosts文件。

Multi on:表示在/etc/hosts文件中指定的主机是否可以有多个地址,拥有多个IP地址的主机一般称为多穴主机。

Nospoof on:表示不允许对该服务器进行IP地址欺骗。IP欺骗是一种攻击系统安全的手段,通过把IP地址伪装成别的计算机,来取得其他计算机的信任。

4./etc/sysconfig/network文件

文件/etc/sysconfig/network用来指定服务器上的网络配置信息,下面是/etc/sysconfig/network文件内容的示例。

[root@redhat2 ~]# cat /etc/sysconfig/network

NETWORKING=yes  //是否配置网络

HOSTNAME=redhat2  //表示计算机的主机名

5./etc/hosts文件

当计算机启动时,在可以查询DNS以前,计算机需要查询一些主机名到IP地址的匹配。这些匹配信息存放在/etc/hosts文件中。在没有域名服务器的情况下,系统上的所有网络程序都通过查询该文件来解析对应于某个主机名的IP地址。

[root@redhat2 ~]# cat /etc/hosts

192.168.12.11   redhat2

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

[root@redhat2 ~]#

最左边一列是计算机IP地址,中间一列是主机名,最后面的列都是该主机的别名。一旦配置完计算机的网络配置文件,应该重新启动网络以使修改生效。

6./etc/services文件。

文件/etc/services定义了Linux系统中所有服务的名称、协议类型、服务的端口等信息。/etc/services文件是一个服务名和服务端口对应的数据库文件,下面是/etc/services文件内容的示例。

二.Linux网络命令

在Linux系统中提供了大量的网络命令用于网络配置、网络测试以及网络诊断,如ifconfig,ping,netstat,traceroute,arp以及tcpdump等。

1.traceroute

使用tracerout命令可以显示数据包到目标主机之间的路径。

Traceroute  [-dFlnrvx] [-f<存活数值>] [-g<网关>]…[-I <网络界面>] [-m<存活数值>] [-p<通信端口>] [-s<来源地址>][-t<服务类型>][-w<超时秒数>][主机名称或IP地址][数据包大小]。

2.ifconfig

使用ifconfig命令可以显示或设置计算机网卡的IP地址。

命令语法:

[root@redhat2 ~]# ifconfig --help

Usage:

ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]

[add <address>[/<prefixlen>]]

[del <address>[/<prefixlen>]]

[[-]broadcast [<address>]]  [[-]pointopoint [<address>]]

[netmask <address>]  [dstaddr <address>]  [tunnel <address>]

[outfill <NN>] [keepalive <NN>]

[hw <HW> <address>]  [metric <NN>]  [mtu <NN>]

[[-]trailers]  [[-]arp]  [[-]allmulti]

[multicast]  [[-]promisc]

[mem_start <NN>]  [io_addr <NN>]  [irq <NN>]  [media <type>]

[txqueuelen <NN>]

[[-]dynamic]

[up|down] …

例1:配置网卡eth3的IP地址,同时激活该设备。

[root@redhat2 ~]# ifconfig eth3 192.168.12.121 netmask 255.255.255.0 up

例2:配置网卡eth3别名设备eth3:1的IP的地址。

[root@redhat2 ~]# ifconfig eth3:1 192.168.12.0

例3:激活网卡eth3:1设备。

[root@redhat2 ~]# ifconfig eth3:1 up

例4:查看所有的网卡网络接口配置。

[root@redhat2 ~]# ifconfig

eth2      Link encap:Ethernet  HWaddr 00:0C:29:53:BB:56

inet addr:192.168.12.11  Bcast:192.168.12.255  Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe53:bb56/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:873 errors:0 dropped:0 overruns:0 frame:0

TX packets:915 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:91453 (89.3 KiB)  TX bytes:414896 (405.1 KiB)

eth3      Link encap:Ethernet  HWaddr 00:0C:29:53:BB:60

inet addr:192.168.12.121  Bcast:192.168.12.255  Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe53:bb60/64 Scope:Link

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

RX packets:124 errors:0 dropped:0 overruns:0 frame:0

TX packets:134 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:12196 (11.9 KiB)  TX bytes:17381 (16.9 KiB)

eth3:1    Link encap:Ethernet  HWaddr 00:0C:29:53:BB:60

inet addr:192.168.12.0  Bcast:192.168.12.255  Mask:255.255.255.0

UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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:914 errors:0 dropped:0 overruns:0 frame:0

TX packets:914 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:45860 (44.7 KiB)  TX bytes:45860 (44.7 KiB)

[root@redhat2 ~]#

例5:禁用网卡eth3:1设备。

[root@redhat2 ~]# ifconfig eth3:1 down

3.ping

使用ping命令可用于测试与目标计算机之间的连通性。

[root@redhat2 ~]# ping --help

ping: invalid option -- '-'

Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]

[-p pattern] [-s packetsize] [-t ttl] [-I interface or address]

[-M mtu discovery hint] [-S sndbuf]

[ -T timestamp option ] [ -Q tos ] [hop1 ...] destination

[root@redhat2 ~]#

例1:测试与 192.168.12.121计算机的连通性,要求返回4个ICMP数据包。

[root@redhat2 ~]# ping -c 4 192.168.12.121

PING 192.168.12.121 (192.168.12.121) 56(84) bytes of data.

64 bytes from 192.168.12.121: icmp_seq=1 ttl=64 time=0.158 ms

64 bytes from 192.168.12.121: icmp_seq=2 ttl=64 time=0.069 ms

64 bytes from 192.168.12.121: icmp_seq=3 ttl=64 time=0.067 ms

64 bytes from 192.168.12.121: icmp_seq=4 ttl=64 time=0.037 ms

--- 192.168.12.121 ping statistics ---

4 packets transmitted, 4 received, 0% packet loss, time 3002ms

rtt min/avg/max/mdev = 0.037/0.082/0.158/0.046 ms

[root@redhat2 ~]#

4.netstat

使用netstat命令可用于显示网络状态的信息。

[root@redhat2 ~]# netstat --help

usage: netstat [-veenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}

netstat [-vnNcaeol] [<Socket> ...]

netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [delay]

-r, --route                display routing table

-I, --interfaces=<Iface>   display interface table for <Iface>

-i, --interfaces           display interface table

-g, --groups               display multicast group memberships

-s, --statistics           display networking statistics (like SNMP)

-M, --masquerade           display masqueraded connections

-v, --verbose              be verbose

-n, --numeric              don't resolve names

--numeric-hosts            don't resolve host names

--numeric-ports            don't resolve port names

--numeric-users            don't resolve user names

-N, --symbolic             resolve hardware names

-e, --extend               display other/more information

-p, --programs             display PID/Program name for sockets

-c, --continuous           continuous listing

-l, --listening            display listening server sockets

-a, --all, --listening     display all sockets (default: connected)

-o, --timers               display timers

-F, --fib                  display Forwarding Information Base (default)

-C, --cache                display routing cache instead of FIB

-T, --notrim               stop trimming long addresses

-Z, --context              display SELinux security context for sockets

<Iface>: Name of interface to monitor/list.

例1:显示网络接口状态信息。

[root@redhat2 ~]# netstat -i

Kernel Interface table

Iface       MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg

eth2       1500   0      883      0      0      0      916      0      0      0 BMRU

eth3       1500   0      366      0      0      0      309      0      0      0 BMRU

lo        16436   0     1034      0      0      0     1034      0      0      0 LRU

[root@redhat2 ~]#

例2:显示内核路由表信息。

[root@redhat2 ~]# netstat -r

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

192.168.12.0    *               255.255.255.0   U         0 0          0 eth3

192.168.12.0    *               255.255.255.0   U         0 0          0 eth2

[root@redhat2 ~]#

三.chkconfig和service命令

在Linux系统上可以使用chkconfig和service命令控制服务的启动、停止和重新启动,两者之间的区别在于使用service命令控制服务可以马上生效,而使用chkconfig命令控制服务需要等计算机重新启动后才会生效。

1.chkconfig命令

使用chkconfig命令主要用来设置下次重启计算机以后启动、停止服务,使用chkconfig命令不会立即启动或停止一项服务。

[root@redhat2 ~]# chkconfig --help

chkconfig version 1.3.49.3 - Copyright (C) 1997-2000 Red Hat, Inc.

This may be freely redistributed under the terms of the GNU Public License.

usage:   chkconfig [--list] [--type <type>] [name]

chkconfig --add <name>

chkconfig --del <name>

chkconfig --override <name>

chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>

[root@redhat2 ~]#

例1:查看各种不同的运行等级中各项服务的状况。

[root@redhat2 ~]# chkconfig --help

chkconfig version 1.3.49.3 - Copyright (C) 1997-2000 Red Hat, Inc.

This may be freely redistributed under the terms of the GNU Public License.

usage:   chkconfig [--list] [--type <type>] [name]

chkconfig --add <name>

chkconfig --del <name>

chkconfig --override <name>

chkconfig [--level <levels>] [--type <type>] <name> <on|off|reset|resetpriorities>

[root@redhat2 ~]# chkconfig --list

NetworkManager  0:off   1:off   2:on    3:on    4:on    5:on    6:off

abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off

abrt-oops       0:off   1:off   2:off   3:on    4:off   5:on    6:off

abrtd           0:off   1:off   2:off   3:on    4:off   5:on    6:off

acpid           0:off   1:off   2:on    3:on    4:on    5:on    6:off

atd             0:off   1:off   2:off   3:on    4:on    5:on    6:off

auditd          0:off   1:off   2:on    3:on    4:on    5:on    6:off

avahi-daemon    0:off   1:off   2:off   3:on    4:on    5:on    6:off

bluetooth       0:off   1:off   2:off   3:on    4:on    5:off   6:off

cpuspeed        0:off   1:on    2:on    3:on    4:on    5:on    6:off

crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off

例2:列出named服务在各个运行级别上的运行状态。

[root@redhat2 ~]# chkconfig --list bluetooth

bluetooth       0:off   1:off   2:off   3:on    4:on    5:off   6:off

[root@redhat2 ~]#

例3:在运行级别5,6上启动bluetooth服务。

[root@redhat2 ~]# chkconfig --list bluetooth

bluetooth       0:off   1:off   2:off   3:on    4:on    5:off   6:off

[root@redhat2 ~]# chkconfig --level 56 bluetooth  on

[root@redhat2 ~]# chkconfig --list bluetooth

bluetooth       0:off   1:off   2:off   3:on    4:on    5:on    6:on

[root@redhat2 ~]#

2.service命令

使用service命令可以启动或停止守护进程,service命令执行后会立即生效。

[root@redhat2 ~]# service --help

Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]

[root@redhat2 ~]#

例1:启动 bluetooth服务。

[root@redhat2 ~]# service  bluetooth start

Enabling Bluetooth devices:

[root@redhat2 ~]#

例2:查看 bluetooth服务运行状态。

[root@redhat2 ~]# service  bluetooth status

Usage: /etc/init.d/bluetooth {start|stop}

例3:重启bluetooth服务。

[root@redhat2 ~]# service bluetooth restart

Usage: /etc/init.d/bluetooth {start|stop}

[root@redhat2 ~]#

例4:停止bluetooth服务。

[root@redhat2 ~]# service bluetooth stop

Stopping Bluetooth services:

[root@redhat2 ~]#

Linux网络基本配置的更多相关文章

  1. Linux网络基础配置

    这是看itercast视频的笔记 Linux网络基础配置 以太网连接 在Linux中,以太网接口被命令为:eth0, eth1等, 0,1代表网卡编号 通过lspci命令可以查看网上硬件信息(如果是u ...

  2. Linux入门-6 Linux网络基本配置

    1. 网络基础知识 网络编址 IP编址 子网掩码 同一网络主机之间通信--MAC地址 不同网络之间的通信 路由 域名 DNS 基本网络参数 2. Linux网络基础配置 以太网连接 配置网络信息 网络 ...

  3. Linux网络属性配置命令和管理详解

    一.Linux网络属性配置 1.Linux主机接入到网络方式 IP/NETMASK:实现本地网络通信 路由(网关):可以进行跨网络通信 DNS服务器地址:基于主机名的通信,Linux可以有三个DNS地 ...

  4. Linux网络属性配置

    目录 IP地址分类 如何将Linux主机接入到网络中 网络接口的命名方式 ifcfg系列命令 如何配置主机名 如何配置DNS服务器指向 iproute2系列命令 Linux管理网络服务 永久生效配置路 ...

  5. Linux网络相关配置

    一.修改网卡相关配置 Linux网络参数是在/etc/sysconfig/network-scripts/ifcfg-eth0中设置,其中ifcfg-eth0表示是第一个网卡,如果还有另外一块网卡,则 ...

  6. Linux 网络基本配置

    一.Linux网络配置文件 1.  /etc/sysconfig/network-scripts/ifcfg-eth0 文件 在Red Hat系统中,系统网络设备的配置文件保存在/etc/syscon ...

  7. Linux网络基础设施配置

    1.TCP/IP网络配置文件 /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network /etc/host.conf /etc/ ...

  8. Linux入门基础(四):Linux网络基本配置

    网络基础 ip编址 ip编址是一个双层编址方案(网络部分和主机部分),一个ip地址标识一个主机(或一个网卡接口) 现在应用最广泛的是IPv4编址,已经开始逐渐向IPv6编址切换 IPv4地址32位长, ...

  9. Linux 入门记录:十五、Linux 网络基本配置

    一.以太网(Ethernet) 以太网(Ethernet)是一种计算机局域网技术.IEEE 组织的 IEEE 802.3 标准制定了以太网的技术标准,它规定了包括物理层的连线.电子信号和介质访问层协议 ...

随机推荐

  1. 编写中断例程7ch:计算word型数据的平方

    实现计算一个word型数据的平方. 这是安装程序. assume cs:code code segment start: mov ax, cs mov ds, ax mov si, offset sq ...

  2. apache2.4设置外网访问问题

    Apache 从2.2升级到 Apache2.4.x 后配置文件 httpd.conf 的设置方法有了大变化,以前是将 deny from all 全部改成 Allow from all 实现外网访问 ...

  3. PSP第九周

    一.表格 C(分类) C(内容) S(开始时间) ST(结束时间) I(打断时间) △(净工作时间) 学习 UML 12:30 13:20 0 50 编码 编码 20:00 22:10 0 130 学 ...

  4. gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,

    1195: 相信我这是水题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 821  Solved: 219 Description GDUT中有个风云人 ...

  5. mysql 求最小值/最大值

    计算所有人最低工资和最高工资,需分别用到min()和max()函数.(请注意,MIN和MAX函数会忽略NULL值) select min(sal) as min_sal , max(sal) as m ...

  6. SQL Server系统存储过程

    1. execute sp_databases   查询当前所有数据库大致信息(名称,大小等) 2. exec sp_helpdb [Myschool] 返回数据库的所有详细信息(数据库大小,位置,文 ...

  7. android studio 中 添加.so 文件

    传送门: http://jingyan.baidu.com/article/e3c78d644baaf23c4d85f57d.html 注意在Build.gradle中 添加的位置

  8. 开发adobe ane分享

    最近的项目使用adobe air开发,不可能避免的要使用到ane,项目初期的时候,使用了网上搜索到的了一些开源ane,最后发现,很多都不完善,要么版本太久,要么BUG很多,无人维护,所以下决心自己开发 ...

  9. js中二维数组的初始化

    在编程过程中,很多情况下(涉及到坐标.层级操作)我们都会用到二维数组,下面介绍介绍几种二维数组初始化的方法: 方法一.直接定义并且初始化,这种情况适用于数量和值已知的数组: var arr=[[&qu ...

  10. SQL Server 开发-语法学习

    一.定义变量 --简单赋值 declare @a int print @a --使用select语句赋值 ) select @user1='张三' print @user1 ) print @user ...