network网络配置

-------------------------网络-Network-------------------------------------

'a'---ssh登录

1.ssh user@rhel //需要配置/etc/hosts:192.168.0.148 rhel

2.ssh user@192.168.0.148


'b'---netstat
- Print [network connections], [routing tables], [interface statistics],
[masquerade connections], [multicast memberships]


1.[network connetions]:

//--查看监听的进程sockets信息:

-n:Show numerical addresses instead of trying to determine symbolic host, port or user names.
-l:Show only listening sockets.
-t:tcp
-u:utp
-p: Show the PID and name of the program to which each socket belongs.

1.netstat -nltp

2.netstat -lup


--------------------------网络配置---------------------------------------------





------网卡配置
1.ifconfig eth0 | lo //查看第一块网卡配置|loopback环路接口配置:127.0.0.1
2.ifconfig eth0 192.168.12.25 netmask 255.255.255.0 //修改IP
ifconfig eth0 192.168.0.159/24 //CIDE:无类别域间路由寻址方式(目的:减少互联网路由表项目)
3.ifconfig eth0 up | down //开启或关闭网卡eth0
4.ifconfig eth0:0 192.168.50.50/27
# 仔细看那个接口, eth0:0 。那就是在该网络接口上,再仿真一个网络接口,
# 亦即是在一个网卡上面设置多个 IP 的意思啦

5.hostname //查看本地系统名称

6.ifconfig interface //查看MAC地址(硬件地址)

7.arp //显示或更改IP-MAC地址转换表(ARP:地址解析协议)
arp -a //显示IP-MAC地址转换表
arp -n //不显示主机名,只显示IP地址(当DNS出问题时,仍然可以用此命令查看)


8.


------修改IP
1.setup //进入修改页面
2.service network restart //修改IP后重启network,时更改生效
3.ping 192.142.33.32

------相关文件
0./etc/sysconfig/network

1./etc/sysconfig/network-scripts/ifcfg-lo //回还接口的配置信息

2./etc/sysconfig/network-scripts/ifcfg-eth0 //eth0的配置信息
//ifcfg-eth0决定 setup的图形管理 和 resolv.conf,如果只改变setup图形管理中的网络设置|resolv.conf则不会更改ifcfg-eth0;通过service network restart即可回复eth0设置。
//ifcfg-eth0中没有DNS的配置则每次重新插上网线时,resolv.conf的DNS被清空,导致无法上网,此时设置ifcfg-eth0中BOOTPROTO=dhcp即可,即动态获得ip;详情查看Documents/backup/ifcfg-eth0文件

3./etc/resolv.conf //DNS服务器的IP等相关信息


4./etc/nsswitch.conf //nsswitch.conf(name service switch configuration 名称服务切换配置文件)
规定通过那些 entry(记录) 以及 按照什么顺序来查找特定的信息。

5./etc/hosts //保存常用的域名|主机名及对应的IP,以便快速查询
//格式:(IP | 主机名 | 别名). 可将别名改为local,则当 ping local 可自动转换为127.0.0.1

5./etc/host.conf //规定主机解析域名时查询顺序,如order hosts,bind先查询/etc/hosts文件,在查询DNS服务器;是否允许主机有多个IP,即设置多个虚拟网卡multi on

6./etc/protocols //描述TCP/IP提供的各种网络互联协议及对应官方协议号

7./etc/services //列出了:不同的网络服务使用的 TCP/UDP 端口

8./etc/rc.d/init.d/network //和下面的文件互为硬链接

9./etc/init.d/network //启动/关闭网络的 脚本文件(Bring up/down networking)
//service network restart调用的就是该脚本文件


------网络接口的启用|禁用

1./etc/rc.d/init.d/network status|start|stop|restart|reload

-------常用命令
1.traceroute www.baidu.com

----- route - show / manipulate the IP routing table(显示或修改路由表)

注:'最重要的作用'--设置到达指定主机或网络的静态路由(通过一个网络接口)
//static routes to specific hosts or networks via an interface

2.route //(displays the current contents of the routing tables.)显示路由表
// 路由表中的每一项都被看作是一个路由,

route -e //use netstat(8)-format for displaying the routing table
//所以该命令等价与netstat -r

route -ee //generate a very long line with all parameters from the routing table.

-----通过 add && del 修改路由表

1.route add [-host] 169.254.192.123(Win7 OS 的IP) gw localhost [dev eth0]//添加-host 路由记录(不能少任何一项)([dev eth0]可选,会由系统指定默认值_)
route add 200.200.200.2 gw 169.254.192.123(Win OS IP) //网关必须时可 reachable或写入hosts文件中,即必须有效,host‘s IP地址可任意

route add RHEL gw localhost dev eth0 //RHEL已经写入hosts.

2.route del 169.254.192.123 //删除-host 路由记录(不能多任何一项)

3.route add -net 200.150.99.0/24 gw 169.254.192.123 //添加-net 路由记录(设置网关)

route add -net 200.150.100.0/24 dev eth0 //添加-net 路由记录(设置数据包被发送的Iface接口)

route add -net 200.150.100.0/24 dev eth0 gw RHEL //同时设置 gw dev

route add -net 200.150.100.0 netmask 255.255.255.0 dev eth0

4.route del -net 200.150.99.0/24 //删除-net 路由记录
route del -net 200.150.100.0/24

/**路由表每一项(即路由)意义(以第二行为例):
* 本机发往200.150.99.0网段的数据包
* 1.首先被转发给网络接口‘lo’,
* 2.然后经过网关169.254.192.123
* 3.最终发往200.150.99.0网段
**/

Destination Gateway Genmask Flags Metric Ref Use Iface
169.254.192.123 localhost.local 255.255.255.255 UGH 0 0 0 lo
169.254.192.121 169.254.192.123 255.255.255.255 UGH 0 0 0 lo
200.150.99.0 169.254.192.123 255.255.255.0 UG 0 0 0 lo
192.168.0.0 * 255.255.255.0 U 1 0 0 eth0
200.150.100.0 * 255.255.255.0 U 0 0 0 eth0 //(dev eth0)
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
default localhost 0.0.0.0 UG 0 0 0 eth0
我在IBM工作,可以为大家内部推荐IBM各种职位 IBM全球职位尽在以下链接(请在浏览器中打开,QQ/微信 会阻止): http://ibmreferrals.com/ 很乐意为感兴趣的小伙伴分享:我的面试经验^_^ 如需咨询,请邮件发送以下邮箱,有问必回 1026096425@qq.com
原文地址:https://www.cnblogs.com/jackydalong/p/2408770.html