(十二)Linux基础之网络配置
2016-06-12 11:07
543 查看
1.网络基础知识
(1)一台主机如果可以连接公网,比如访问www.baidu.com,那么这台主机必然会有
Ipaddress
GATEWAY
dns
(2)Ipaddress
ipv4
2进制32位
254.254.254.254/255.255.255.0
11111110.11111110.11111110.11111110/11111111.11111111.11111111.00000000
2.ip设定
ifconfig###查看或者临时设定主机ip的工具(同ip addr show)
ifconfig 网络接口##查看这个接口上的 ip
systemctl restart network###重新启动网络基本服务
systemctl restart NetworkManager###网络智能管理服务
(1)方法一:图形网络配置方式
nm-connection-editor##图形中的网络设定工具
nmtui##文本中的网络设定工具
(2)方法二:ifconfig临时设定ip(重启服务或关机重启电脑ip不能保存)
ifconfig 网络接口 ip netmask 子网掩码####临时设定ip
ifconfig eth0 172.25.254.100 netmask 255.255.255.0
(3)方法三:nmcli命令设定ip(不会随重启服务或电脑而)
nmcli device show
nmcli device status
nmcli device disconnec eth0##断开网的连接
nmcli connection delete连接名称###删除此连接
nmcli connection add con-name westos ifname eth0 type ethernet autoconnect yes ####添加动态网络
nmcli connection add con-name westos ifname eth0 type ethernet ip4 ip/24###静态网络
v nmcli命令nmcli device show
nmcli device status
nmcli device disconnect eth0
nmcli device connect eth0
nmcli connection edit "System westos1"
nmcli connection modify "System westos1" ipv4.addresses 172.25.254.101/24
nmcli connection modify "System westos1" ipv4.dns 172.25.254.1
nmcli connection modify "System westos1" ipv4.method auto
nmcli connection modify "System westos1" ipv4.method manual
nmcli connection delete "System westos1"
nmcli connection add con-name eth0 ifname eth0 type ethernet ip4 172.25.254.100 gw4 172.25.254.254
nmcli connection modify eth0 ipv4.dns 172.25.254.254
v 我们可以通过 TAB 键补全命令,当你忘记这个命令的语法时只需要按下 TAB 就可以看到选项列表。
v 也可以通过文件查询
(4)方法四:通过配置文件,重启服务来配置地址
网络配置文件
/etc/sysconfig/network-scripts/###网络配置目录
###动态网络配置###
vim ifcfg-xxx###网络配置文件格式
DEVICE=eth0##指定文件管理的设备名称
BOOTPROTO=dhcp##dhcp动态获取,none和static都表示静态网络
ONBOOT=yes##开机自动激活设备
NAME=hello##指定网络链接的名字为hello
###静态网络配置###
vim ifcfg-xxx ###网络配置文件格式
DEVICE=eth0 ##指定文件管理的设备名称
BOOTPROTO=static|none##dhcp动态获取,none和static都表示静态网络
ONBOOT=yes ##开机自动激活设备
NAME=hello##指定链接名字
IPADDR=172.25.254.100##设定ip为172.25.254.100
NETMASK=255.255.255.0##子网掩码为255.255.255.0
PREFIX=24##子网掩码为255.255.255.0
3.域名解析
(1)ip映射文件
/etc/hosts
ip 主机名称
(2)dns服务器的指向文件
vim /etc/resolv.conf
nameserver 172.25.254.254
vim /etc/sysconfig/network-scripts/ifcfg-xxx
DNS1=172.25.254.254
PEERDNS=yes|no###配置文件是否会修改/etc/resolv.conf no表示不修改
v 设置本地的DNS,编辑/etc/hosts文件
v 默认情况下,/etc/hosts优先级高于DNS,但是可以在/etc/nsswitch.conf中修改优先级v 当本地设置的DNS地址与不同时,默认本地为主,但我们可以通过/etc/nesswitch来编辑它39行hosts : files dns ##hosts优先于DNShosts : dns files ##DNS优先于hosts
4.网关gateway
网关就是路由器上和我们的主机处在同一个网段上的ip,连接两个不同的网段,使之能通信。
vim /etc/sysconfig/network-scripts/ifcfg-xxx
GATEWAY=网关地址
ip route ##查看系统当中网关
route -n ##查看系统中路由表
traceroute ip/网址##访问该网址要经过的路径
v 示例
v 用一个脚本完成IP的设定
v netport//查看服务所开启的端口-a//所有-n //不作解析-p//显示端口所使用的进程-l//只显示-e//扩展,更详细的信息-t//tcp格式文件-u//
(1)一台主机如果可以连接公网,比如访问www.baidu.com,那么这台主机必然会有
Ipaddress
GATEWAY
dns
(2)Ipaddress
ipv4
2进制32位
254.254.254.254/255.255.255.0
11111110.11111110.11111110.11111110/11111111.11111111.11111111.00000000
2.ip设定
ifconfig###查看或者临时设定主机ip的工具(同ip addr show)
ifconfig 网络接口##查看这个接口上的 ip
systemctl restart network###重新启动网络基本服务
systemctl restart NetworkManager###网络智能管理服务
(1)方法一:图形网络配置方式
nm-connection-editor##图形中的网络设定工具
nmtui##文本中的网络设定工具
(2)方法二:ifconfig临时设定ip(重启服务或关机重启电脑ip不能保存)
ifconfig 网络接口 ip netmask 子网掩码####临时设定ip
ifconfig eth0 172.25.254.100 netmask 255.255.255.0
(3)方法三:nmcli命令设定ip(不会随重启服务或电脑而)
nmcli device show
nmcli device status
nmcli device disconnec eth0##断开网的连接
nmcli connection delete连接名称###删除此连接
nmcli connection add con-name westos ifname eth0 type ethernet autoconnect yes ####添加动态网络
nmcli connection add con-name westos ifname eth0 type ethernet ip4 ip/24###静态网络
v nmcli命令nmcli device show
nmcli device status
nmcli device disconnect eth0
nmcli device connect eth0
nmcli connection edit "System westos1"
nmcli connection modify "System westos1" ipv4.addresses 172.25.254.101/24
nmcli connection modify "System westos1" ipv4.dns 172.25.254.1
nmcli connection modify "System westos1" ipv4.method auto
nmcli connection modify "System westos1" ipv4.method manual
nmcli connection delete "System westos1"
nmcli connection add con-name eth0 ifname eth0 type ethernet ip4 172.25.254.100 gw4 172.25.254.254
nmcli connection modify eth0 ipv4.dns 172.25.254.254
v 我们可以通过 TAB 键补全命令,当你忘记这个命令的语法时只需要按下 TAB 就可以看到选项列表。
v 也可以通过文件查询
(4)方法四:通过配置文件,重启服务来配置地址
网络配置文件
/etc/sysconfig/network-scripts/###网络配置目录
###动态网络配置###
vim ifcfg-xxx###网络配置文件格式
DEVICE=eth0##指定文件管理的设备名称
BOOTPROTO=dhcp##dhcp动态获取,none和static都表示静态网络
ONBOOT=yes##开机自动激活设备
NAME=hello##指定网络链接的名字为hello
###静态网络配置###
vim ifcfg-xxx ###网络配置文件格式
DEVICE=eth0 ##指定文件管理的设备名称
BOOTPROTO=static|none##dhcp动态获取,none和static都表示静态网络
ONBOOT=yes ##开机自动激活设备
NAME=hello##指定链接名字
IPADDR=172.25.254.100##设定ip为172.25.254.100
NETMASK=255.255.255.0##子网掩码为255.255.255.0
PREFIX=24##子网掩码为255.255.255.0
3.域名解析
(1)ip映射文件
/etc/hosts
ip 主机名称
(2)dns服务器的指向文件
vim /etc/resolv.conf
nameserver 172.25.254.254
vim /etc/sysconfig/network-scripts/ifcfg-xxx
DNS1=172.25.254.254
PEERDNS=yes|no###配置文件是否会修改/etc/resolv.conf no表示不修改
v 设置本地的DNS,编辑/etc/hosts文件
v 默认情况下,/etc/hosts优先级高于DNS,但是可以在/etc/nsswitch.conf中修改优先级v 当本地设置的DNS地址与不同时,默认本地为主,但我们可以通过/etc/nesswitch来编辑它39行hosts : files dns ##hosts优先于DNShosts : dns files ##DNS优先于hosts
4.网关gateway
网关就是路由器上和我们的主机处在同一个网段上的ip,连接两个不同的网段,使之能通信。
vim /etc/sysconfig/network-scripts/ifcfg-xxx
GATEWAY=网关地址
ip route ##查看系统当中网关
route -n ##查看系统中路由表
traceroute ip/网址##访问该网址要经过的路径
v 示例
v 用一个脚本完成IP的设定
v netport//查看服务所开启的端口-a//所有-n //不作解析-p//显示端口所使用的进程-l//只显示-e//扩展,更详细的信息-t//tcp格式文件-u//
相关文章推荐
- 【日志类】解决了okHttp的使用问题
- 虚拟机安装Ubuntu三种网络模式
- Java发送http的get、post、put请求
- 关于 httpUrlConnection 的 setDoOutput 与 setDoInput
- HTTP Live Streaming直播(iOS直播)技术分析与实现
- 安卓6版本中删除Apache HTTP客户端支持
- 检查网络是否可用(Android)
- 基于linux的TCP网络聊天室设计与实现
- 军方让我做即时通讯,好好交代一下网络安全问题(附源码)
- 网络编程中需要考虑的一些情况
- iOS访问https ssl和tls双向加密
- Android官方开发文档Training系列课程中文版:网络操作之网络管理
- Kali进行web渗透笔记(十一)
- Kali进行web渗透笔记(十)
- Kali进行web渗透笔记(九)
- Kali进行web渗透笔记(六)
- 网络监控nagios小结
- Kali进行web渗透笔记(五)
- okhttp
- Kali进行web渗透笔记(四)