码迷,mamicode.com
首页 > 系统相关 > 详细

linux菜鸟基础学习 (六) 网络

时间:2018-10-20 10:17:17      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:config   cmd   otp   version   ade   dhcp服务   服务配置   命名规则   switch   

linux下的网络配置

1.什么是IP ADDRESS

  internet protocol ADDRESS ##网络协议地址
    ipv4    internet protocol version 4
    1.2x32
    ip是由32个0和1组成
    11111110.11111110.11111110.11111110 = 254.254.254.254

2.子网掩码

用来划分网络区域
子网掩码非0的位对应的ip上的数字表示这个ip的网络位
子网掩码0位对应的数字是ip的主机位
网络位表示网络区域
主机位表示网络区域里的某台主机

3.ip通信判定

网络位一致,主机位不一致的两个IP可以直接通信
172.25.254.1/24     24=255.255.255.0
172.25.254.2/24
172.25.0.1/16

4.网络设定工具

ping        ##检测网络是否通畅
ifconfig    ##查看或设定网络接口
ifconfig device ip/24   ##设定网络
ifconfig device down    ##关闭
ifconfig device up  ##开启

技术分享图片

技术分享图片

技术分享图片

5.图形方式设定ip

1.nm-connection-editor

2.nmtui

6.命令方式设定网络

nmcli

nmcli device connect eth0   ##启用eth0网卡
nmcli device disconnect eth0    ##关闭eth0网卡
nmcli device show eth0      ##查看网卡信息
nmcli device status eth0    ##查看网卡服务接口信息

nmcli connection show
nmcli connection down westos
nmcli connection up westos
nmcli connection delete westos
nmcli connection add type ethernet con-name westos ifname eth0 ip4 172.25.254.100/24
nmcli connection modify westos ipv4.method auto
nmcli connection modify westos ipv4.method manual
nmcli connection modify westos ipv4.addresses 172.25.254.150/24

技术分享图片

技术分享图片

技术分享图片

技术分享图片

技术分享图片

技术分享图片

技术分享图片

技术分享图片

7.管理网络配置文件

网络配置目录
/etc/sysconfig/network-scripts
网络配置文件的命名规则
ifcfg-xxx
DEVICE=xxx          ##设备名称
BOOTPROTO=dhcp|static|none  ##设备的工作方式
ONBOOT=yes          ##网络服务开启时自动激活网卡
IPADDR=             ##IP地址
PREFIX=24           ##子网掩码
NETMASK=255.255.255.0       ##子网掩码

示例:
静态网络设定文件
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=172.25.254.100
NETMASK=255.255.255.0
BOOTPROTO=none
NAME=westos

systemctl restart network

技术分享图片

技术分享图片

技术分享图片

技术分享图片

一块网卡上配置多个IP
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
IPADDR0=172.25.254.100
NETMASK0=255.255.255.0
BOOTPROTO=none
NAME=westos
IPADDR1=172.25.0.100
PREFIX1=24

systemctl restart network

ip addr show eth0

8.lo回环接口

9.网关

1.把真实主机变成路由器

firewall-cmd --list-all
firewall-cmd --permanent --add-masquerade
firewall-cmd --reload

2.设定虚拟机网关
vim /etc/sysconfig/network
GATEWAY=172.25.254.250

10.设定dns

doamin name system

vim /etc/hosts          ##本地解析文件
ip      域名
61.135.169.121  www.baidu.com

vim /etc/resolv.conf        ##dns指向文件
nameserver  114.114.114.114

vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=114.114.114.114

11.设定解析优先级

系统默认
/etc/hosts > /etc/resolv.conf

vim /etc/nsswitch.conf
39 hosts:   files   dns ##/etc/hosts优先

vim /etc/nsswitch.conf
39 hosts:       dns files     ##/etc/resolv.conf优先

12.dhcp服务配置

linux菜鸟基础学习 (六) 网络

标签:config   cmd   otp   version   ade   dhcp服务   服务配置   命名规则   switch   

原文地址:http://blog.51cto.com/14016326/2306716

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!