virtualbox ubuntu 20.04 固定ip网络设置

916 阅读1分钟

1. 环境

  • virtualbox
  • ubuntu 20.04

2. 配置

2.1 网络模式和网卡设置

image.png

virtual box 配置桥接网络模式,一张网卡。

image.png

2.2 固定ip设置

image.png

vim /etc/netplan/00-installer-config.yaml

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s3:
      dhcp4: false
      dhcp6: false
      addresses:
        - 10.0.0.12/24   // 24代表24位子网掩码
      gateway4: 10.0.0.254    // 和host配置成一样
      nameservers:
        addresses: [114.114.114.114,8.8.8.8,192.168.1.1,10.0.0.254]   // dns和host配置成一样
  version: 2
  renderer: networkd

3. 测试

ping hostip
host ping 虚拟机 // 能ping通则同一网段的其他机器也可以ping通
测试是否通 外网

root:~# ping www.baidu.com
PING www.wshifen.com (45.113.192.102) 56(84) bytes of data.

64 bytes from 45.113.192.102 (45.113.192.102): icmp_seq=1 ttl=44 time=210 ms

或者 apt-get update ,通过终端返回看是否通外网

root@:~# apt-get update

Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease

Hit:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease

Hit:3 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease

Hit:4 http://mirrors.aliyun.com/ubuntu focal-backports InRelease

Hit:5 http://mirrors.aliyun.com/ubuntu focal-security InRelease

其他排查命令

lsof -i :5432
nc -vv 10.0.0.181 5432
tcpdump -i enp0s3 tcp port 5432 \