Linux 网络配置基础 1
网络相关命令与网卡配置文件
OS:Red**Hat EnterpriseLinux6.4
1 ifconfig 查看 / 设置网卡**
ifconfig 查看所有活动网卡信息
ifconfig -a 查看所有网卡信息
ifconfig eth0 查看具体网卡信息
ifconfig eth0 up/down 激活 / 禁用网卡
ifup/ifdown eth0 激活 / 禁用网卡(重新读取配置文件)
[root@rhel64 ~]# ifconfig
查看具体网卡信息
[root@rhel64 ~]# ifconfig eth0
临时设置 eth0 网卡子接口 ip,子网卡 ip 须使用静态配置。
[root@rhel64 ~]# ifconfig eth0:0 192.168.7.101
[root@rhel64 ~]# ifconfig
[root@rhel64 ~]# ifconfig eth0:0 down
[root@rhel64 ~]# ifconfig
2 ip、ethtool 查看网卡配置、属性
[root@rhel64 ~]# ip
查看网络接口配置情况
[root@rhel64 ~]# ip addr
[root@rhel64 ~]# ip addr show eth0
查看网络接口属性信息
[root@rhel64 ~]# ethtool eth0
3 ping 测试网络通信
[root@rhel64 ~]# ping 192.168.6.6 -c 4
4 route -n 查看路由信息
[root@rhel64 ~]# route -n
[root@rhel64 ~]# ip route
如果需手动指定具体路由,可编辑修改配置文件
/etc/sysconfig/network-scripts/route-eth0
5 traceroute 查看主机间路由
测试从当前主机到目标主机间经过的网络节点
[root@rhel64 ~]# traceroute 192.168.6.6
windows 中对应命令 tracert
6 hostname 查看主机名
[root@rhel64 ~]# hostname
hostname 命令也可以用来临时设置主机名,当前有效,重启后恢复配置文件中值
7 netstat 查看网络连接状态
[root@rhel64 ~]# netstat —help
[root@rhel64 ~]# netstat -lntup
[root@rhel64 ~]# netstat -antup
8 /etc/sysconfig/network
全局配置文件
[root@rhel64 ~]# cat /etc/sysconfig/network
NETWORKING 全局网络开关
HOSTNAME 主机名
GATEWAY 全局网关配置,多个网卡时可在具体网卡配置文件指定
9 具体网卡配置文件
[root@rhel64 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE 网卡名称 要与配置文件名中一致
TYPE=Ethernet 以太网
ONBOOT=yes 重启操作系统后激活网卡
BOOTPROTO none 或者 static 是静态设置 ip;dhcp 是自动获取
IPADDR ip 地址
GATEWAY 网关 默认路由
PREFIX 子网掩码,或使用 NETMASK=255.255.255.0
10 本地主机名解析 /etc/hosts
保存主机名与 IP 地址的映射记录
[root@rhel64 ~]# cat /etc/hosts
[root@rhel64 ~]# vi /etc/hosts
[root@rhel64 ~]# ping rhel64 -c2
win7 中也有对应文件
11 网络配置总结
吕星昊
2016.1.18
来自 “ITPUB 博客” ,链接:http://blog.itpub.net/29475508/viewspace-1978184/,如需转载,请注明出处,否则将追究法律责任。
http://blog.itpub.net/29475508/viewspace-1978184/