CentOS下的网络配置文件说明
CentOS网络配置主要涉及到以下四个文件:
1、/etc/sysconfig/network
在CentOS官方网站上给出了如下说明:
The/etc/sysconfig/networkfile is used to specify information about the desired network configuration. The following values may be used:
NETWORKING=, where<value>is one of the following boolean values:<value>yes— Networking should be configured.no— Networking should not be configured.
HOSTNAME=, where<value>should be theFully Qualified Domain Name(FQDN), such as<value>hostname.expample.com, but can be whatever hostname is necessary.GATEWAY=, where<value>is the IP address of the network's gateway.<value>GATEWAYDEV=, where<value>is the gateway device, such as<value>eth0. Configure this option if you have multiple interfaces on the same subnet, and require one of those interfaces to be the preferred route to the default gateway.NISDOMAIN=, where<value>is the NIS domain name.<value>NOZEROCONF=, where setting<value>to<value>truedisables the zeroconf route.By default, the zeroconf route (169.254.0.0) is enabled when the system boots.
从上面的说明中可以看出,该文件是用来配置系统初始化网络信息的,例如是否启动网络,主机名称,网关信息等。
2、/etc/sysconfig/network-scripts/ifcfg-eth0
当我们进入/etc/sysconfig/network-scripts/目录中时,会发现这里存在很多的可执行脚本,那么这个目录下的都是些什么东西呢?先看官方说明:
This directory contains the following network-related configuration files:
Network configuration files for each configured network interface, such as
ifcfg-eth0for theeth0Ethernet interface.Scripts used to bring network interfaces up and down, such as
ifupandifdown.Scripts used to bring ISDN interfaces up and down, such as
ifup-isdnandifdown-isdn.Various shared network function scripts which should not be edited directly.
原来该目录下的都是网络参数配置文件以及配置网络时用到的脚本。其中,经常接触的是ifcfg-eth0,该文件用来配置第一块网卡(eth0)参数的配置文件。如果需要配置第二块网卡信息,那么就创建一个ifcfg-eth1;第三块是ifcfg-eth2,以此类推。其典型的配置信息(静态IP地址)如下:
DEVICE=eth0 BOOTPROTO=none ONBOOT=yes NETWORK=10.0.1.0 NETMASK=255.255.255.0 IPADDR=10.0.1.27 USERCTL=no
如果需要配置成系统启动时动态分配IP地址,那么配置信息可能是这样的:
DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes
我一直很想知道这里面的参数信息到底有多少项,每一项的可选值又是什么,但这个念头每次都只是在我配置网络参数时一闪而过,没有深究。如果需要全面了解,那么请参考官方说明文档:http://www.centos.org/docs/5/html/5.2/Deployment_Guide/s2-networkscripts-interfaces-eth0.html
顺便说一下,给第一块网卡(eth0)配置多个IP的方法是:将ifcfg-eth0拷贝一个eth0:1,在eth0:1中指定新的参数即可,同一块网卡可以支持配置255个IP。给其他网卡配置多个IP地址的方法以此类推。
3、/etc/resolv.conf
该文件用于配置DNS服务器地址信息,官方文档这样描述:
This file specifies the IP addresses of DNS servers and the search domain. Unless configured to do otherwise, the network initialization scripts populate this file. For more information about this file, refer to the resolv.conf man page.
如果想知道该文件的具体配置方法,请参看man手册。一个典型的配置信息如下:
nameserver 211.157.24.248
nameserver 202.106.46.151
search localhost
4、/etc/hosts
从名字就可以看出,该文件用来指定IP地址与主机名对应关系的,相当于Windows系统下的HOSTS文件。所以,如果网内没有DNS服务器,或者需要加快主机名的解析速度,可以在该文件中指定主机名和对应的IP地址。官方文档描述如下:
The main purpose of this file is to resolve hostnames that cannot be resolved any other way. It can also be used to resolve hostnames on small networks with no DNS server. Regardless of the type of network the computer is on, this file should contain a line specifying the IP address of the loopback device (127.0.0.1) as localhost.localdomain. For more information, refer to the hosts man page.
补充:/etc/sysconfig/networking/
这个文件夹里的东西是干什么的,很多人都不太清楚,我也不例外。我从官方文档中找到了答案:
The /etc/sysconfig/networking/ directory is used by the Network Administration Tool(system-config-network) and its contents should not be edited manually. Using only one method for network configuration is strongly encouraged, due to the risk of configuration deletion.
原来这个文件夹里的东西都是给网络管理员工具(system-config-network)用的啊,而且还警告用户不要手动编辑这里面的文件,难怪我一直不知道是干什么用的呢!
CentOS下的网络配置文件说明的更多相关文章
- CentOS下查看网络状态
查看网络状态:lsof -Pnl +M -i4 显示ipv4服务及监听端情况netstat -anp 所有监听端口及对应的进程netstat -tlnp 功能同上 网络基本命令 (1)network ...
- VMware 虚拟机centos下链接网络配置
1.点击Network Adapter 设置如下图所示,首先我们在虚拟机中将网络配置设置成NAT, 2.计算机右键->管理->服务和应用程序->服务,启动如下两个服务 3.在etc/ ...
- centos下docker网络桥接
停止服务 停止docker0网卡 Ip link set dev docker0 down 删除docker0 Brctl delbr docker0 进入到网卡的配置文件创建桥接网络br0 Brct ...
- centos下网络的基本配置方法讲解
上一篇中我们已经成功安装了我们的centos系统,但是我们可能发现我们安装的centos上不了网,所以这一章我们来说说如何配置centos来连接外网和局域网. 我们首先来认识一下linux下部分网络配 ...
- mac与centos下redis的安装与配置
前言 最近在用redis,下面简单写一下mac和centos下redis的安装与配置方法. 安装 mac下面 安装命令:brew intall redis 运行命令:brew services sta ...
- CentOS下Yum的$releasever和$basearch的取值
CentOS下Yum源配置文件中如CentOS-Base.repo的$releasever和$basearch的取值 $releasever的值,这个表示当前系统的发行版本,可以通过如下命令查看: r ...
- centos下修改docker连接docker_host默认方式为tls方式
1.安装docker,请参考官网文档 centos下安装docker 2.安装完成应该可以使用docker的各种命令连接docker host.docker host运行在本机上,但与localhos ...
- CentOS虚拟机如何设置共享文件夹,并在Windows下映射网络驱动器?
一.为什么要这么做? 最近在做Linux下的软件开发,但又想使用Windows下的编程工具“Source Insight”. 亲测有效. 要注意查看smb.conf.example,centos7的 ...
- [转]CentOS虚拟机如何设置共享文件夹,并在Windows下映射网络驱动器?
CentOS虚拟机如何设置共享文件夹,并在Windows下映射网络驱动器? 转自这里 一.为什么要这么做? 最近在做Linux下的软件开发,但又想使用Windows下的编程工具“Source Insi ...
随机推荐
- 第三个Sprint完结工作 用场景来规划测试工作.
一.根据用户使用场景测试: 1.流程 典型群体 群体 张小明 年龄 7-12岁 职业 小学生 收入 压岁钱还有零花钱 能力 看一些简单的数,做一些相对简单的事 爱好 玩游戏 典型场景 张小明平时喜欢玩 ...
- 在Python中,令values=[0,1,2];values[1]=values,为何结果是[0,[...],2]?
转载自:http://www.zhihu.com/question/21000872/answer/16856382>>> values = [0, 1, 2] >>&g ...
- [转载]在Android C/C++层添加LOG调试
原文地址:C/C++层添加LOG调试">在Android C/C++层添加LOG调试作者:谢轩昂 在Android C/C++层添加LOG调试,并且在Logcat中输出的方法 第一步: ...
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) G 优先队列
G. Car Repair Shop time limit per test 2 seconds memory limit per test 512 megabytes input standard ...
- c#部分---用结构体的题目- //请输入班级人数,输入每个人的学号,姓名,和语文分数、数学分数和英语分数(要求使用结构体)
//请输入班级人数,输入每个人的学号,姓名,和语文分数.数学分数和英语分数(要求使用结构体), //求班级里两个语文分数是最高分的学生的所有信息:数学分数是最高分的两个学生的所有信息:英语平均分 建立 ...
- jquery的ajax异步请求接收返回json数据
http://www.jb51.net/article/51122.htm jquery的ajax异步请求接收返回json数据方法设置简单,一个是服务器处理程序是返回json数据,另一种就是ajax发 ...
- GRANT ALL PRIVILEGES 限制某个或所有客户端都可以连接至mysql
GRANT ALL PRIVILEGES 1. 改表法.可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mys ...
- timus 1109 Conference(二分图匹配)
Conference Time limit: 0.5 secondMemory limit: 64 MB On the upcoming conference were sent M represen ...
- 《灰帽Python-黑客和逆向工程师的Python编程》学习记录
ctypes是Python语言的一个外部库,提供和C语言兼容的数据类型,可以很方便的调用C DLL中的函数. 操作环境:CentOS6.5 Python版本:2.66 ctypes是强大的,强大到本书 ...
- mave之:java的web项目必须要的三个jar的pom形式
jsp-api javax.servlet-api jstl <!-- jsp --> <dependency> <groupId>javax.servlet< ...