Linux网络配置
2018-03-27 09:33
120 查看
网络及网络配置00000001 . 0000 0001
1111 1111 .0000 0000
0000 0001 .0000 0010
0000 0001 .0000 0000
1.0
1.1 --> 2.1
1.0
1.1 --> 1.2
1.0 1.0
IPv4点分十进制:
0000 0000 -1111 1111
0-255
221.34.23.12
网络地址:
主机地址:
32位二进制
A类: 255.0.0.0, 8:
0 000 0001 - 0111 1111
127个A类,127用于回环,1-126
2^7-1个A类
容纳多少个主机:2^24-2
主机位全0:网络地址
主机位全1:广播地址
B类:255.255.0.0, 16
10 00 0000- 10 11 1111
128-191
129.1.0.0.
130.1.0.0
64个B类,2^14个B类网
容纳多少个主机:2^16-2
C类:255.255.255.0, 24
110 0 0000 - 110 1 1111
192-223
32个C类, 2^21个C类网
容纳多个少个主机:2^8-2
私有地址:
A类:10.0.0.0/8
B类:172.16.0.0/16-172.31.0.0/16
C类:192.168.0.0/24-192.168.255.0/24
路由:选路
ICANN, IANA
D类:
1110 0000 - 1110 1111
224-239
E类:
主机接入网络:
IP
NETMASK
GATEWAY
HOSTNAME
DNS1
DNS2
DNS3
手动指定
DHCP:Dynamic HostConfiguration Protocol
169.254.
路由
Linux: 网络属于内核的功能
RHEL5:/etc/modprobe.conf
alias
RHEL6:/etc/udev/rules.d/70-persistent-net.rules
cd/etc/udev/rules.d/
cat70-persistent-net.rules
ifconfig [ethX]
-a:显示所有接口的配置住处
ifconfig ethXIP/MASK [up|down]
配置的地址立即生效,但重启网络服务或主机,都失效
网络服务:
/etc/init.d/network{start|stop|restart|status}
rhel6:/etc/init.d/NetworkManager{start|stop|restart|status}
ifconfig eth110.1.1.1/8
ifconfig eth1down
ifconfig eth1up
ifconfig eth1 192.168.10.123/24
ping192.168.10.123
网关:
route
add:添加
-host:主机路由
-net 网络路由
-net 0.0.0.0 默认路由
route add-net|-host DEST gw NEXTHOP
route adddefault gw NEXTHOP
del:删除
-host
-net
route del -net 10.0.0.0/8 [gw NEXTHOP]
route del -net 0.0.0.0
route del default
所作出的改动重启网络服务或主机后失效
查看:
route -n:以数字方式显示各主机或端口信息
192.168.10.123
route add -net10.0.0.0/8 via gw 192.168.10.1
route adddefault gw 192.168.10.1
route -n
网络配置文件:
/etc/sysconfig/network
网络接口配置文件:
/etc/sysconfig/network-scripts/ifcfg-INTERFACE_NAME
DEVICE=: 关联的设备名称,要与文件名的后半部“INTERFACE_NAME”保持一致;
BOOTPROTO={static|none|dhcp|bootp}:引导协议;要使用静态地址,使用static或none;dhcp表示使用DHCP服务器获取地址;
IPADDR=: IP地址
NETMASK=:子网掩码
GATEWAY=:设定默认网关;
ONBOOT=:开机时是否自动激活此网络接口;
HWADDR=: 硬件地址,要与硬件中的地址保持一致;可省;
USERCTL={yes|no}:是否允许普通用户控制此接口;
PEERDNS={yes|no}:是否在BOOTPROTO为dhcp时接受由DHCP服务器指定的DNS地址;
不会立即生效,但重启网络服务或主机都会生效;
路由:
/etc/sysconfig/network-scripts/route-ethX
添加格式一:
DEST via NEXTHOP
vim route-eth1
192.168.10.0/24via 10.10.10.254
/etc/init.d/networkrestart
route -n
添加格式二:
ADDRESS0=
NETMASK0=
GATEWAY0=
vim route-eth1
ADDRESS0=192.168.10.0
NETMASK0=255.255.255.0
GATEWAY0=10.10.10.254
!/etc 重启网路服务
route -n
DNS服务器指定方法只有一种:
/etc/resolv.conf
nameserverDNS_IP_1
nameserverDNS_IP_2
指定本地解析:
/etc/hosts
主机IP 主机名 主机别名
172.16.0.1 www.magedu.com www
DNS-->/etc/hosts-->DNS
配置主机名:
hostnameHOSTNAME
立即生效,但不是永久有效;
/etc/sysconfig/network
HOSTNAME=
RHEL5:
setup: system-config-network-tui
system-config-network-gui
ifconfig, 老旧
iproute2
ip
link: 网络接口属性
addr: 协议地址
route: 路由
link
show
ip -s link show
set
ip link set DEV {up|down}
addr
add
ip addr add ADDRESS dev DEV
ip addr add 10.2.2.2/8 dev eth1
ip addr show
ping 10.2.2.2
del
ip addr del ADDRESS dev DEV
ip addr del 10.2.2.2 dev eth1
show
ip addr show dev DEV to PREFIX
ip addr add 192.168.100.3/24 deveth1 label eth1:0
ip addr show eth1
ip addr show eth1 to 192.168.100/24
flush
ip addr flush dev DEV to PREFIX
ip addr flush eht1 to 10/8
ip addr show eth1
一块网卡可以使用多个地址:
网络设备可以别名:
eth0
ethX:X, eth0:0, eth0:1, ...
配置方法:
ifconfig ethX:X IP/NETMASK
ifconfig eth0:0 172.16.200.33/16
/etc/sysconfig/network-scripts/ifcfg-ethX:X
DEVICE=ethX:X
非主要地址不能使用DHCP动态获取;
ip
eth1, 添加个地址192.168.100.1
ip addr add192.168.100.1/24 dev eth1 label eth1:0
primary address
secondaryadress
192.168.100.6
10.0.1.0/24,192.168.100.6
路由:
route add -net10.0.1.0/24 gw 192.168.100.6
ip route add to10.0.1.0/24 dev eth1 via 192.168.100.6
add, change, show, flush, replace
ifconfig eth0,172.16.200.33/16
ifconfig eth0:0172.16.200.33/16
TCP:
URG
SYN
ACK
PSH
RST
FIN
netstat命令:
-r: 显示路由表
-n: 以数字方式显示
-t: 建立的tcp连接
-u: 显示udp连接
-l: 显示监听状态的连接
-p: 显示监听指定的套接字的进程的进程号及进程名
1111 1111 .0000 0000
0000 0001 .0000 0010
0000 0001 .0000 0000
1.0
1.1 --> 2.1
1.0
1.1 --> 1.2
1.0 1.0
IPv4点分十进制:
0000 0000 -1111 1111
0-255
221.34.23.12
网络地址:
主机地址:
32位二进制
A类: 255.0.0.0, 8:
0 000 0001 - 0111 1111
127个A类,127用于回环,1-126
2^7-1个A类
容纳多少个主机:2^24-2
主机位全0:网络地址
主机位全1:广播地址
B类:255.255.0.0, 16
10 00 0000- 10 11 1111
128-191
129.1.0.0.
130.1.0.0
64个B类,2^14个B类网
容纳多少个主机:2^16-2
C类:255.255.255.0, 24
110 0 0000 - 110 1 1111
192-223
32个C类, 2^21个C类网
容纳多个少个主机:2^8-2
私有地址:
A类:10.0.0.0/8
B类:172.16.0.0/16-172.31.0.0/16
C类:192.168.0.0/24-192.168.255.0/24
路由:选路
ICANN, IANA
D类:
1110 0000 - 1110 1111
224-239
E类:
主机接入网络:
IP
NETMASK
GATEWAY
HOSTNAME
DNS1
DNS2
DNS3
手动指定
DHCP:Dynamic HostConfiguration Protocol
169.254.
路由
Linux: 网络属于内核的功能
RHEL5:/etc/modprobe.conf
alias
RHEL6:/etc/udev/rules.d/70-persistent-net.rules
cd/etc/udev/rules.d/
cat70-persistent-net.rules
ifconfig [ethX]
-a:显示所有接口的配置住处
ifconfig ethXIP/MASK [up|down]
配置的地址立即生效,但重启网络服务或主机,都失效
网络服务:
/etc/init.d/network{start|stop|restart|status}
rhel6:/etc/init.d/NetworkManager{start|stop|restart|status}
ifconfig eth110.1.1.1/8
ifconfig eth1down
ifconfig eth1up
ifconfig eth1 192.168.10.123/24
ping192.168.10.123
网关:
route
add:添加
-host:主机路由
-net 网络路由
-net 0.0.0.0 默认路由
route add-net|-host DEST gw NEXTHOP
route adddefault gw NEXTHOP
del:删除
-host
-net
route del -net 10.0.0.0/8 [gw NEXTHOP]
route del -net 0.0.0.0
route del default
所作出的改动重启网络服务或主机后失效
查看:
route -n:以数字方式显示各主机或端口信息
192.168.10.123
route add -net10.0.0.0/8 via gw 192.168.10.1
route adddefault gw 192.168.10.1
route -n
网络配置文件:
/etc/sysconfig/network
网络接口配置文件:
/etc/sysconfig/network-scripts/ifcfg-INTERFACE_NAME
DEVICE=: 关联的设备名称,要与文件名的后半部“INTERFACE_NAME”保持一致;
BOOTPROTO={static|none|dhcp|bootp}:引导协议;要使用静态地址,使用static或none;dhcp表示使用DHCP服务器获取地址;
IPADDR=: IP地址
NETMASK=:子网掩码
GATEWAY=:设定默认网关;
ONBOOT=:开机时是否自动激活此网络接口;
HWADDR=: 硬件地址,要与硬件中的地址保持一致;可省;
USERCTL={yes|no}:是否允许普通用户控制此接口;
PEERDNS={yes|no}:是否在BOOTPROTO为dhcp时接受由DHCP服务器指定的DNS地址;
不会立即生效,但重启网络服务或主机都会生效;
路由:
/etc/sysconfig/network-scripts/route-ethX
添加格式一:
DEST via NEXTHOP
vim route-eth1
192.168.10.0/24via 10.10.10.254
/etc/init.d/networkrestart
route -n
添加格式二:
ADDRESS0=
NETMASK0=
GATEWAY0=
vim route-eth1
ADDRESS0=192.168.10.0
NETMASK0=255.255.255.0
GATEWAY0=10.10.10.254
!/etc 重启网路服务
route -n
DNS服务器指定方法只有一种:
/etc/resolv.conf
nameserverDNS_IP_1
nameserverDNS_IP_2
指定本地解析:
/etc/hosts
主机IP 主机名 主机别名
172.16.0.1 www.magedu.com www
DNS-->/etc/hosts-->DNS
配置主机名:
hostnameHOSTNAME
立即生效,但不是永久有效;
/etc/sysconfig/network
HOSTNAME=
RHEL5:
setup: system-config-network-tui
system-config-network-gui
ifconfig, 老旧
iproute2
ip
link: 网络接口属性
addr: 协议地址
route: 路由
link
show
ip -s link show
set
ip link set DEV {up|down}
addr
add
ip addr add ADDRESS dev DEV
ip addr add 10.2.2.2/8 dev eth1
ip addr show
ping 10.2.2.2
del
ip addr del ADDRESS dev DEV
ip addr del 10.2.2.2 dev eth1
show
ip addr show dev DEV to PREFIX
ip addr add 192.168.100.3/24 deveth1 label eth1:0
ip addr show eth1
ip addr show eth1 to 192.168.100/24
flush
ip addr flush dev DEV to PREFIX
ip addr flush eht1 to 10/8
ip addr show eth1
一块网卡可以使用多个地址:
网络设备可以别名:
eth0
ethX:X, eth0:0, eth0:1, ...
配置方法:
ifconfig ethX:X IP/NETMASK
ifconfig eth0:0 172.16.200.33/16
/etc/sysconfig/network-scripts/ifcfg-ethX:X
DEVICE=ethX:X
非主要地址不能使用DHCP动态获取;
ip
eth1, 添加个地址192.168.100.1
ip addr add192.168.100.1/24 dev eth1 label eth1:0
primary address
secondaryadress
192.168.100.6
10.0.1.0/24,192.168.100.6
路由:
route add -net10.0.1.0/24 gw 192.168.100.6
ip route add to10.0.1.0/24 dev eth1 via 192.168.100.6
add, change, show, flush, replace
ifconfig eth0,172.16.200.33/16
ifconfig eth0:0172.16.200.33/16
TCP:
URG
SYN
ACK
PSH
RST
FIN
netstat命令:
-r: 显示路由表
-n: 以数字方式显示
-t: 建立的tcp连接
-u: 显示udp连接
-l: 显示监听状态的连接
-p: 显示监听指定的套接字的进程的进程号及进程名
相关文章推荐
- [Linux] Ubuntu 18 LTS netplan 网络配置
- Linux系统基础网络配置老鸟精华篇 【转】
- Linux 网络接口配置文件及相关工具 (v0.1b)
- VMware12中的Linux系统利用NAT网络连接方式访问外网配置
- Linux——网络配置介绍
- Linux网络配置代码
- vm上linux虚拟机NAT网络模式的配置
- Linux下ip配置与网络重启
- Linux网络基础配置
- linux 中关于网络的配置方法
- linux 网络配置
- Linux网络设置1——Linux网络环境配置
- VMware10中的Linux系统利用NAT网络连接方式访问外网配置
- linux中配置网络出现 SIOCADDRT: No such process
- Linux的基础网络配置
- Linux下的网络配置命令
- Linux服务器的网络配置详解
- VMware下Linux网络配置攻略
- 11 TCP/IP 基础与Linux的网络配置
- linux 使用cups配置网络打印机