• 系统网络配置 基于Ubuntu系统的网络配置指导


    Ubuntu系统网络配置

    Ubuntu系统网络配置总结

    • 主机名
    • 网卡名称
    • 网卡IP配置

    1.设置主机名

    方法一:通过文件修改主机名,需要reboot永久生效

    #查看主机名
    root@ubuntu1804:/home/hong# hostname
    ubuntu1804
    #通过文件修改主机名,需要reboot,永久生效
    root@ubuntu1804:/home/hong# vim /etc/hostname 
    root@ubuntu1804:/home/hong# cat /etc/hostname 
    nginx.ubuntu.org
    #查看修改后主机名
    root@nginx:/home/hong# hostname
    nginx.ubuntu.org
    root@nginx:/home/hong# echo $HOSTNAME
    nginx.ubuntu.org
    

    方法二:用hostname命令修改主机名,临时生效,重启主机后不存在

    #用hostname命令修改主机名,临时生效,重启主机后不存在
    root@ubuntu1804:/home/hong# hostname mysql.ubuntu.org
    #修改后立即查看
    root@ubuntu1804:/home/hong# hostname
    mysql.ubuntu.org
    #开启其他终端查看
    root@mysql:/home/hong# echo $HOSTNAME
    mysql.ubuntu.org
    

    2.修改网卡名

    第一步:修改/etc/default/grub文件

    修改方法:

    1. 手动修改/etc/default/grub
    2. 命令修改/etc/default/grub
    #方法一:手动修改/etc/default/grub文件
    root@nginx:/home/hong# vim /etc/default/grub
    GRUB_CMDLINE_LINUX="net.ifnames=0"       #原配置为:GRUB_CMDLINE_LINUX=""
    #方法二:
    root@nginx:/home/hong# sed -Ei.bak 's/^(GRUB_CMDLINE_LINUX=.*)"$"/\1net.ifnames=0"/' /etc/default/grub
    
    #查看修改
    root@nginx:/home/hong# cat /etc/default/grub 
    # If you change this file, run 'update-grub' afterwards to update
    # /boot/grub/grub.cfg.
    # For full documentation of the options in this file, see:
    #   info -f grub -n 'Simple configuration'
        
    GRUB_DEFAULT=0
    GRUB_TIMEOUT_STYLE=hidden
    GRUB_TIMEOUT=0
    GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
    GRUB_CMDLINE_LINUX="net.ifnames=0"
    

    第二步:生成新的grub.cfg文件

    root@nginx:/home/hong# grub-mkconfig -o /boot/grub/grub.cfg     #两种方式二选一 grub-mkconfig和 update-grub
    root@nginx:/home/hong# update-grub
    root@nginx:/home/hong# grep net.ifnames /boot/grub/grub.cfg     #确认修改内容
    root@nginx:/home/hong# ip a
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
    #ip a 查看修改的网卡结果,网口名已经从ens33改为eth0
    

    3.配置网卡IP

    1. 设置动态IP
    2. 设置静态IP

    设置动态IP:

    root@nginx:/etc/netplan# vim 01-network-manager-all.yaml 
    root@nginx:/etc/netplan# cat /etc/netplan/01-network-manager-all.yaml 
    # Let NetworkManager manage all devices on this system
    network:
      version: 2
      renderer: NetworkManager
      ethernets:
        eth0:
        dhcp4: yes
    #执行命令使配置生效
    root@nginx:/etc/netplan# netplan apply
    

    设置静态IP:

    root@nginx:/etc/netplan# vim /etc/netplan/01-network-manager-all.yaml 
    root@nginx:/etc/netplan# cat /etc/netplan/01-network-manager-all.yaml 
    # Let NetworkManager manage all devices on this system
    network:
      version: 2
      renderer: NetworkManager
      ethernets:
        eth0:
          dhcp4: no
          addresses: [10.0.0.51/24]
          gateway4: 10.0.0.2
          nameservers:
             addresses: [223.6.6.6,114.114.114.114]   #两种方式二选一
             - 223.6.6.6
             - 114.114.114.114
    #执行命令使配置生效
    root@nginx:/etc/netplan# netplan apply 
    

    4. 配置xshell连接Ubuntu主机

    由于xshell远程连接Ubuntu是通过ssh协议的,所以需要给Ubuntu安装ssh服务

    1)给ubuntu安装ssh服务
    $ sudo apt-get -y install openssh-server
    $ sudo service ssh restart

    2)测试主机通讯
    在Ubuntu上测试xshell所在主机
    > ping ubuntu ip
    在xshell主机测试Ubuntu主机
    $ ping xshellhost ip

    3)配置shell远程登录Ubuntu

    • 新建连接
    • name: Ubuntu
    • protocol:SSH
    • Host: Ubuntu IP
    • port number: 22
    • 点击 connect
    • 输入Ubuntu账号密码
  • 相关阅读:
    敏捷实践12 条原则
    源代码就是设计
    什么是软件设计?
    极限编程与敏捷开发
    Windows下配置Nginx代理Django
    你的评估是我的决策
    JavaScript通用库(一)
    系统分层组织结构
    ASP.NET MVC 4 小项目开发总结
    非等值折半查找
  • 原文地址:https://www.cnblogs.com/hony625/p/15740075.html
Copyright © 2020-2023  润新知