安装完vmware虚拟机软件后,会带来一些设备:
vmnet0:用于桥接模式下的虚拟交换机
vmnet1:用于仅主机模式下的虚拟交换机
vmnet8:用户nat模式下的虚拟交换机
vmnet1 Link encap:Ethernet:虚拟网卡
vmnet8 Link encap:Ethernet:虚拟网卡
Linux下基本的网络配置
网卡类型:eth 以太网卡 eth0 第一块以太网卡,eth1 第2块,,,
查看网卡信息
# lspci |grep -i eth 查看网卡
02:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 0c)
# mii-tool eth0 查看网卡的网线是否ok
eth0: negotiated 100baseTx-FD flow-control, link ok 说明网线ok
filed :失败 说明网线有问题
ifconfig命令:
ifconfig -a :查看所有的网卡信息
ifconfig ethX:查看某个网卡信息
临时给eth0网卡配置ip地址(重启网络失效):
ifconfig eth0 192.168.1.1/24
或者
ifconfig eth0 192.168.1.2 netmask 255.255.255.0
给网卡配置子接口:
ifconfig eth0:1 10.1.1.222/16
或者
ifconfig eth0:1 10.1.1.222 netmask 255.255.0.0
临时开启和关闭网卡(重启网络失效):
ifconfig eth0 down
ifconfig eth0 up
ifconfig eth0:1 up
永久开启和关闭网卡:
ifup eth0
ifdown eth0
临时自动获取IP地址:
dhclient eth0
重启网络:
service network restart|stop|start
或者
/etc/init.d/network restart|stop|start
NetworkManager服务:
rhel6自带的网络图形化工具,类似于网络小助手,自动连接可用的网络,该服务会干扰网络配置,eg:dns
建议关闭该服务
service NetworkMananger stop 临时关闭
# chkconfig --list|grep NetworkManager
NetworkManager 0:off 1:off 2:on 3:on 4:on 5:on 6:off
服务名称 数字代表系统的运行级别;on代表开机自启动;off代表开机不自动启动
# service NetworkManager stop
Stopping NetworkManager daemon: [ OK ]
# chkconfig --list|grep NetworkManager
NetworkManager 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# service NetworkManager status
NetworkManager is stopped
# chkconfig --level 35 NetworkManager off
# chkconfig --list|grep NetworkManager
NetworkManager 0:off 1:off 2:on 3:off 4:on 5:off 6:off
网络相关的配置文件:
/etc/sysconfig/network-scripts/ifcfg-ethX 网卡的配置文件(局部)
/etc/sysconfig/network 网络全局配置文件
/etc/hosts 域名解析的文件
/etc/resolv.conf 配置dns文件
配置静态IP地址:
方法一:
setup工具(图形化工具)
方法二:通过修改配置文件直接更改ip地址
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 设备名
TYPE=Ethernet 网卡类型
ONBOOT=yes yes代表重启激活网卡;no代表不激活
BOOTPROTO=none 获取IP的方式;dhcp自动获取;none和static代表静态
NM_CONTROLLED=yes 受NetworkManager服务影响
IPADDR=10.1.1.1 IP地址
NETMASK=255.255.255.0 子网掩码
GATEWAY=10.1.1.254 网关
DNS1=10.1.1.254 dns服务器
HWADDR=00:0c:29:f4:3d:41 MAC地址
IPV6INIT=no 不是用ipv6
USERCTL=no 是否允许普通用户启动或者关闭网络
ping命令:
ping IP|hostname
# ping 10.1.1.254
PING 10.1.1.254 (10.1.1.254) 56(84) bytes of data.
64 bytes from 10.1.1.254: icmp_seq=1 ttl=64 time=0.072 ms
# ping -c 2 10.1.1.254 -c ping次数
PING 10.1.1.254 (10.1.1.254) 56(84) bytes of data.
64 bytes from 10.1.1.254: icmp_seq=1 ttl=64 time=0.316 ms
64 bytes from 10.1.1.254: icmp_seq=2 ttl=64 time=0.221 ms
--- 10.1.1.254 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.221/0.268/0.316/0.050 ms
屏蔽回显信息:
# cat /proc/sys/net/ipv4/icmp_echo_ignore_all
0 代表开启回显;1代表关闭回显
# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
测试:
修改主机名:
查看主机名:
# hostname
# uname -n
hostname 主机名 临时修改 退出后再登录
永久修改:
vim /etc/sysconfig/network
NETWORKING=yes 是否开启网络功能;service network restart
HOSTNAME=node1.uplook.com 主机名
修改完后需要重启系统才生效
/etc/hosts:域名解析的文件
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.1.1.1 node1.uplook.com node1
10.1.1.2 node2.uplook.com node2
注意:前两行不要动
ip地址 主机名 一一对应
指定dns服务器:
# vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 10.1.1.254
nameserver 8.8.8.8
如果hosts文件和dns冲突,优先去找hosts文件
总结:
ping 10.1.1.254——>ifconfig ——>mii-tool eth0——>service network restart——>route -n——>service NetworkManager start——>检查网卡的配置文件
虚拟机快照和克隆:
vim /etc/sysconfig/network-scripts/ifcfg-eth1
eth1..
mv /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth0
rm -rf /etc/udev/rules.d/70-persistent-net.rules
reboot
IP选路
route -n 查看路由信息
添加一条到目标网络的路由
route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0
删除到目标网络的路由
route del -net 192.168.1.0/24
添加一条到目标主机的路由
route add -host 172.16.2.10 gw 10.1.1.254
删除目标主机路由
route del -host 172.16.2.10
添加一条默认路由
route add default gw 10.1.1.254
route del default 删除默认网关
实验:
实现不同网络互通
环境:
A:192.168.0.2
B:10.1.1.1
C:2.2.2.8
B主机:
1、开启路由转发功能:
# cat /proc/sys/net/ipv4/ip_forward
0 代表未开启;1代表开启路由转发功能
# echo 1 > /proc/sys/net/ipv4/ip_forward
# cat /proc/sys/net/ipv4/ip_forward
1
2、添加到A网络和C网络的路由
# route add -net 192.168.0.0/24 dev eth0
# route add -net 2.2.2.0/24 dev eth0
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
2.2.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 10.1.1.254 0.0.0.0 UG 0 0 0 eth0
A和C主机:
修改默认网关为B主机
A主机:
[root@node2 Desktop]# route add -net 10.1.1.0/24 dev eth0
[root@node2 Desktop]# route add default gw 10.1.1.1
[root@node2 Desktop]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 10.1.1.1 0.0.0.0 UG 0 0 0 eth0
C主机:
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.1.1.1 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
2.2.2.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 10.1.1.1 0.0.0.0 UG 0 0 0 eth0
测试验证:
B主机分别pingA主机和C主机
http://www.cnblogs.com/Dodge/articles/4264833.html
问题:学的是什么?
unix linux
1973年 ——>用C语言重新编写——>unix
各大硬件厂商 sun ()hp(hp-ux)IBM(aix)
1979 open source 1984由 理查得.斯多曼 创立了GNU()和自由软件基金会;
GNU项目目的:开发一个完全自由的unix系统;
GPL:
1991年 ——>1994年 1.0 linux 内核
GNU/linux
内核版本:
#uname -r
2.6.32-431.el6.x86_64
2=主版本号
6=次版本号
32=末版本号
431=修订号
el6=系统版本红冒企业版6
x86_64=cpu架构
linux的2大分支:
Debian 系列 (ubuntu) 软件包 *.deb
redhat (centos|openSUSE|Fedora) *.rpm
rehdat linux
unix like (类unix):
特点:
1、完全开源
2、多用户多任务
3、支持多种硬件平台
4、安全稳定
linux系统设计理念:
1、一切皆文件
2、以纯文本的方式来保存系统配置
3、只有唯一的目录树 /
4、小工具哲学 通过多个小工具来完成比较复杂的任务
5、避免人机交互 以参数来完成信息的传递
查看系统版本:
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.5 (Santiago)
[root@demo Desktop]# lsb_release -d
Description: Red Hat Enterprise Linux Server release 6.5 (Santiago)
[root@demo Desktop]# lsb_release -a
Linux组成:
内核、应用程序、文件系统、shell
内核:
1、系统接口调用
2、内存管理
3、文件系统管理
4、进程管理
5、驱动硬件
应用程序:
程序:一堆文件,并不占用系统的运行资源,占用空间
进程:进程是由程序产生,一个程序可以产生一个或者多个进程(线程);占用系统运行资源
文件系统:
组织存放数据的一种方式。数据要存放在硬盘上,必须将硬盘格式化成某种文件系统。
shell:
人机交互的一个桥梁,命令解释器 bash shell 默认的
路径的表示方式:
绝对路径:以根“/”开始
相对路径:相对当前的工作路径而言
思考:
ls /usr/local/bin/../../share/man
/usr/share/man
pwd:查看当前工作路径
.:代表当前工作路径
..:代表上一级工作路径
cd :更改工作路径
Linux的目录树结构:
/(根)
——————————————————————————————————————————
| | | | |
bin sbin etc root home....
/(根目录):
bin:
sbin:
usr:
usr/bin:
usr/sbin:
etc:
boot:
home:
root:
tmp:
media:
mnt:
lib:
dev:
opt:
selinux:
var:
其他补充目录:
/etc/init.d 或者 /etc/rc.d/init.d
/usr/local:
/usr/share:
/var/log:
/usr/src:
文件名:
1、一切皆文件,文件名的最大长度可达255个字符
2、文件名区分大小写(大小写敏感)
3、文件名不要使用特殊字符
大小写字母、数字、下划线
特殊字符:
/:分割符
通配符:
*:
?:
[]:任一单个字符或者一组单个字符
{}:{string1,string2,...}