15158846557 在线咨询 在线咨询
15158846557 在线咨询
所在位置: 首页 > 营销资讯 > 网站运营 > Ubuntu虚拟机网络配置

Ubuntu虚拟机网络配置

时间:2023-06-28 18:27:01 | 来源:网站运营

时间:2023-06-28 18:27:01 来源:网站运营

Ubuntu虚拟机网络配置:先学习vim 和 Ubuntu命令的一些基础知识。

sudo apt-get remove vim-commonsudo apt-get updatesudo apt-get upgradesudo apt-get install vim



首先虚拟机的网络链接模式选为NAT模式

查看宿主机下dhcp,net服务是否正常启动




查看vmware为虚拟机统一提供的网关,这样我们在后续配置虚拟机ip时,保证ip和网关在同一网段下:
点击编辑–虚拟机网络编辑器:




若想要修改这个配置,需要以管理员身份点击下面的更改设置:

接着进行后续操作,选中VMnet8 ,点击NAT设置:

此时我知道我的网关为192.168.52.2。

在linux虚拟机中打开eth0对应网络接口配置文件,修改配置:

cd /etcsudo mkdir sysconfigcd sysconfigsudo mkdir network-scriptscd network-scriptssudo vi ./ifcfg-eth0配置信息如下:

ONBOOT=yesNM_CONTROLLED=yesBOOTPROTO=staticIPADDR=192.168.52.12NETMASK=255.255.255.0GATEWAY=192.168.52.2将其中ONBOOT设置为yes,BOOTPROTO设置为static,由于网关为192.168.52.2,所以这台虚拟机的ip可以设置为192.168.52.*,在此,我们设置为
192.168.52.12,子网掩码NETMASK=255.255.255.0,网关就是之前我们查看的网关地址:GATEWAY=192.168.52.2;

在此,我们要对这个接口配置文件做个介绍:
文件 /etc/sysconfig/network-scripts/ifcfg-eth0在/etc/sysconfig/network-script在这个目录下面,存放的是网络接口(网卡)的脚本文件(控制文件),ifcfg-eth0是默认的第一个网络接口,如果机器中有多网络接口,那么名字就将依此类推ifcfg-eth1,ifcfg-eth2,ifcfg-eth3……(这里面的文件是相当重要的,涉及到网络能否正常工作)。

设置完接口文件保存后,我们要重启网络服务,使配置文件生效

service network restart此时可以通过ping网关来测试是否配置成功

ping 192.168.52.2为了连接外网,我们还要配置dns服务

cd ./networklssudo vim interfaces在里面写入

nameserver 114.114.114.114保存后,执行以下命令

sudo service network-manager restartping www.baidu.com按crtl+c键停止ping,然后重启linux虚拟机。


下载文件

我是从这个链接下载的clash-linux-amd64-v1.6.0.gz(根据你的Linux版本选择合适的版本),将目录切换到下载的clash-linux-amd64-v1.6.0.gz所在的目录,执行以下命令:

gzip -d clash-linux-amd64-v1.6.0.gz再在文件管理器里选择解压得到的文件clash-linux-amd64-v1.6.0,鼠标点击右键,选择重命名,将文件clash-linux-amd64-v1.6.0重命名为clash。

移动到/usr/bin/目录:

mv clash /usr/bin/赋予文件 clash 可执行权限:

sudo chmod +x /usr/bin/clash检查 clash 是否安装成功

clash -v返回以下消息说明安装成功:

Clash v1.6.0 linux amd64 with go1.16.3 Sat May 8 11:30:49 UTC 2021默认配置目录是 ~/.config/clash

配置文件的名称是 config.yml 或者config.ymal

# port of HTTPport: 7890# port of SOCKS5socks-port: 7891# redir port for Linux and macOS# redir-port: 7892allow-lan: false# Rule / Global/ Direct (default is Rule)mode: Rule# set log level to stdout (default is info)# info / warning / error / debug / silentlog-level: info# A RESTful API for clashexternal-controller: 127.0.0.1:9090# you can put the static web resource (such as clash-dashboard) to a directory, and clash would serve in `${API}/ui`# input is a relative path to the configuration directory or an absolute path# external-ui: folder# Secret for RESTful API (Optional)# secret: ""# dns: # enable: true # set true to enable dns (default is false) # ipv6: false # default is false # listen: 0.0.0.0:53 # enhanced-mode: redir-host # nameserver: # - 114.114.114.114 # - tls://dns.rubyfish.cn:853 # dns over tls # fallback: # concurrent request with nameserver, fallback used when GEOIP country isn't CN # - tcp://1.1.1.1Proxy:# shadowsocks# The types of cipher are consistent with go-shadowsocks2# support AEAD_AES_128_GCM AEAD_AES_192_GCM AEAD_AES_256_GCM AEAD_CHACHA20_POLY1305 AES-128-CTR AES-192-CTR AES-256-CTR AES-128-CFB AES-192-CFB AES-256-CFB CHACHA20-IETF XCHACHA20# In addition to what go-shadowsocks2 supports, it also supports chacha20 rc4-md5 xchacha20-ietf-poly1305- { name: "ss1", type: ss, server: server, port: 443, cipher: AEAD_CHACHA20_POLY1305, password: "password" }# old obfs configuration remove after prerelease- name: "ss2" type: ss server: server port: 443 cipher: AEAD_CHACHA20_POLY1305 password: "password" plugin: obfs plugin-opts: mode: tls # or http # host: bing.com- name: "ss3" type: ss server: server port: 443 cipher: AEAD_CHACHA20_POLY1305 password: "password" plugin: v2ray-plugin plugin-opts: mode: websocket # no QUIC now # tls: true # wss # skip-cert-verify: true # host: bing.com # path: "/" # headers: # custom: value# vmess# cipher support auto/aes-128-gcm/chacha20-poly1305/none- { name: "vmess", type: vmess, server: server, port: 443, uuid: uuid, alterId: 32, cipher: auto }# with tls- { name: "vmess", type: vmess, server: server, port: 443, uuid: uuid, alterId: 32, cipher: auto, tls: true }# with tls and skip-cert-verify- { name: "vmess", type: vmess, server: server, port: 443, uuid: uuid, alterId: 32, cipher: auto, tls: true, skip-cert-verify: true }# with ws-path and ws-headers- { name: "vmess", type: vmess, server: server, port: 443, uuid: uuid, alterId: 32, cipher: auto, network: ws, ws-path: /path, ws-headers: { Host: v2ray.com } }# with ws + tls- { name: "vmess", type: vmess, server: server, port: 443, uuid: uuid, alterId: 32, cipher: auto, network: ws, ws-path: /path, tls: true }# socks5- { name: "socks", type: socks5, server: server, port: 443 }# socks5 with authentication- { name: "socks", type: socks5, server: server, port: 443, username: "username", password: "password" }# with tls- { name: "socks", type: socks5, server: server, port: 443, tls: true }# with tls and skip-cert-verify- { name: "socks", type: socks5, server: server, port: 443, tls: true, skip-cert-verify: true }# http- { name: "http", type: http, server: server, port: 443 }# http with authentication- { name: "http", type: http, server: server, port: 443, username: "username", password: "password" }# with tls (https)- { name: "http", type: http, server: server, port: 443, tls: true }# with tls (https) and skip-cert-verify- { name: "http", type: http, server: server, port: 443, tls: true, skip-cert-verify: true }Proxy Group:# url-test select which proxy will be used by benchmarking speed to a URL.- { name: "auto", type: url-test, proxies: ["ss1", "ss2", "vmess1"], url: "http://www.gstatic.com/generate_204", interval: 300 }# fallback select an available policy by priority. The availability is tested by accessing an URL, just like an auto url-test group.- { name: "fallback-auto", type: fallback, proxies: ["ss1", "ss2", "vmess1"], url: "http://www.gstatic.com/generate_204", interval: 300 }# load-balance: The request of the same eTLD will be dial on the same proxy.- { name: "load-balance", type: load-balance, proxies: ["ss1", "ss2", "vmess1"], url: "http://www.gstatic.com/generate_204", interval: 300 }# select is used for selecting proxy or proxy group# you can use RESTful API to switch proxy, is recommended for use in GUI.- { name: "Proxy", type: select, proxies: ["ss1", "ss2", "vmess1", "auto"] }Rule:- DOMAIN-SUFFIX,google.com,auto- DOMAIN-KEYWORD,google,auto- DOMAIN,google.com,auto- DOMAIN-SUFFIX,ad.com,REJECT- IP-CIDR,127.0.0.0/8,DIRECT- SOURCE-IP-CIDR,192.168.1.201/32,DIRECT- GEOIP,CN,DIRECT# FINAL would remove after prerelease# you also can use `FINAL,Proxy` or `FINAL,,Proxy` now- MATCH,auto

配置clash.service服务

先按如下命令创建clash.service文件:

cd /lib/systemd/systemsudo vim clash.service向clash.service文件中写入以下内容:

[Unit]Description=clashAfter=network-online.targetWants=network-online.target systemd-networkd-wait-online.service[Service]Type=simpleUser=rootGroup=rootDynamicUser=trueExecStart=/usr/bin/clash -d /etc/clash/Restart=alwaysLimitNOFILE=512000[Install]WantedBy=multi-user.target
下载YAML文件并重新命名
得到Clash的订阅链接,并重命名为config.yaml文件。一定要是config名字。

将下载完成的config.yaml文件(如果是config.yal文件,直接重命名为config.yaml就行了)和 Country.mmdb文件复制到~/.config/clash/

进入~/.config/clash并再复制到/etc/clash(若没有该文件夹就先mkdir创建一个)中

cd ~/.config/clash/cp config.yaml /etc/clash/cp Country.mmdb /etc/clash/然后通过浏览器访问 http://clash.razord.top 进行策略组设置。

随后系统设置,网络设置中添加http代理,IP 127.0.0.1 端口 7890 socks代理,IP 127.0.0.1 端口 7891。

至此重新启动网络:

service network-manager restart至此重新启动本软件执行:

service clash restart至此虚拟机网络配置成功。

关键词:配置,网络,虚拟

74
73
25
news

版权所有© 亿企邦 1997-2025 保留一切法律许可权利。

为了最佳展示效果,本站不支持IE9及以下版本的浏览器,建议您使用谷歌Chrome浏览器。 点击下载Chrome浏览器
关闭