Linux网络属性管理(一)

MarkdownPad Document

Linux网络属性管理(一)


将一台linux主机接入互联网一般需要配置以下几个方面的参数:

IP/mask –>  IP地址和子网掩码

路由 –> 默认网关

DNS服务器


配置方式

静态指定:

  1、ifcfg:ifconfig,route,netstat

  2、ip:object {link,addr,route},ss,tc

  3、配置文件

     system-config-network-tui(setup)

  4、CentOS 7:

     nmcli,nmtui

动态指定

  DHCP:Dynamic Host Configuration Protocol  

配置网络接口

接口命名方式

  CentOS 6:

    以太网:eth[0,1,2,…]

ifconfig命令

ifconfig [interface]
   # ifconfig -a
   # ifcofnig IFACE [up|down]
ifconfig interface [aftype] options | address...
   # ifconfig IFACE IP/mask [up]
   # ifconfig IFACE IP netmask MASK

   注意:立即生效

[root@Daniel ~]# ifconfig -a
eth0  Link encap:Ethernet  HWaddr 00:0C:29:1F:1E:01  
      inet addr:192.168.98.123  Bcast:192.168.98.255  Mask:255.255.255.0
      inet6 addr: fe80::20c:29ff:fe1f:1e01/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:1905 errors:0 dropped:0 overruns:0 frame:0
      TX packets:1300 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000 
      RX bytes:171688 (167.6 KiB)  TX bytes:138181 (134.9 KiB)

lo    Link encap:Local Loopback  
      inet addr:127.0.0.1  Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:0 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0 
      RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@Daniel ~]#

route命令  

路由管理命令

查看:route -n

[root@Daniel ~]# route -n 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.98.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.98.2    0.0.0.0         UG    0      0        0 eth0
[root@Daniel ~]#

添加:route add

route add  [-net|-host]  target [netmask Nm] [gw Gw] [[dev] If]
目标:192.168.1.3  网关:172.16.0.1
    ~]# route add -host 192.168.1.3 gw 172.16.0.1 dev eth0

目标:192.168.0.0 网关:172.16.0.1
    ~]# route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1 dev eth0
    ~]# route add -net 192.168.0.0/24 gw 172.16.0.1 dev eth0

默认路由,网关:172.16.0.1
    ~]# route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.16.0.1
    ~]# route add default gw 172.16.0.1

删除:route del

route del [-net|-host] target [gw Gw] [netmask Nm] [[dev] If]
目标:192.168.1.3  网关:172.16.0.1
    ~]# route del -host 192.168.1.3

目标:192.168.0.0 网关:172.16.0.1
    ~]# route del -net 192.168.0.0 netmask 255.255.255.0

DNS服务器指定

/etc/resolv.conf
    nameserver DNS_SERVER_IP1
    nameserver DNS_SERVER_IP2
    nameserver DNS_SERVER_IP3

正解:FQDN-->IP
    # dig -t A FQDN
    # host -t A FQDN
反解:IP-->FQDN
    # dig -x IP
    # host -t PTR IP

netstart命令

netstat -Print network connections,routings tables,interface statistics,masquerade

显示网络连接:

netstat [--tcp|-t] [--udp|-u] [--raw|-w] [--listening|-l] [--all|-a] [--numeric|-n] [--extend|-e[--extend|-e]]  [--program|-p]
    -t: tcp协议相关
    -u: udp协议相关
    -w: raw socket相关
    -l: 处于监听状态
    -a: 所有状态
    -n: 以数字显示IP和端口;
    -e:扩展格式
    -p: 显示相关进程及PID

    常用组合:
        -tan, -uan, -tnl, -unl

显示路由表

netstat  {--route|-r} [--numeric|-n]
    -r: 显示内核路由表
    -n: 数字格式

显示接口统计数据

netstat  {--interfaces|-I|-i} [iface] [--all|-a] [--extend|-e] [--program|-p] [--numeric|-n] 

# netstat -i
# netstat -I IFACE

原创文章,作者:Daniel-W,如若转载,请注明出处:http://www.178linux.com/18189

(0)
Daniel-WDaniel-W
上一篇 2016-06-12 17:02
下一篇 2016-06-14 15:15

相关推荐

  • 软Raid

    软RAID     一.概念 RAID是多个磁盘合成一个“阵列”来提供更好的性能、冗余、或者两者都提供。 二.作用 提高IO能力: 磁盘并行读写 提高冗余来实现 :磁盘冗余来实现 三.实现方式 外接式磁盘阵列:通过扩展卡提供适配能力 内接式RAID:主板集成RAID控制器 软件RAID:通过OS实现(今天的重点) 四.RAID级别 1. …

    2017-08-29
  • CentOS6.7上编译安装php

    环境:CentOS6.7,minimal安装。 前提条件:安装了编译环境,安装了Apache/Nginx,安装了MySQL/MariaDB。具体安装见:http://www.178linux.com/16583    http://www.178linux.com/17497  1、解决依赖关系: 请配置好yum源(系统安装源及…

    Linux干货 2016-06-03
  • shell脚本编程2

    shell脚本编程2   今天继续学习了shell脚本编程,续之前写的脚本编程1。上次主要学了编程的基础,脚本格式,变量类型及变量的使用,条件测试,数字运算并且进行了部分练习,因为这部分逻辑思维能力要求不是很高,因此记忆起来难度不是特别大。   从今天开始便进入了流程控制以及函数、数组、高级字符串操作、高级变量等内容的学习,总体来说难度和…

    Linux干货 2016-08-16
  • 文本处理工具及grep命令的理解与使用

    1. 文本处理工具   1.1 文件查看命令cat tac     cat命令:连接文件并在标准输出上面显示出来  图 1-1   cat帮助文档        cat [option]…[file]…     &n…

    Linux干货 2016-08-07
  • Linux下软件包安装(rpm,yum)

    Linux下软件包安装(rpm,yum,源代码) 1)    Rpm包管理安装 2)    Yum包程序管理器 3)    本地Yum仓库建制 ======================================= 1) …

    Linux干货 2016-06-22
  • gitlab-ce官方文档查看备录

    gitlab文档 关于gitlab-ce GitLab Community Edition (CE) is available freely under the MIT Expat license. 关于unicorn的workers For&nbs…

    Linux干货 2015-09-06