{"id":433,"date":"2023-02-25T12:24:42","date_gmt":"2023-02-25T04:24:42","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=433"},"modified":"2023-04-29T21:05:38","modified_gmt":"2023-04-29T13:05:38","slug":"vagrant-network-configuration","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/vagrant-network-configuration\/","title":{"rendered":"Vagrant\u7f51\u7edc\u914d\u7f6e"},"content":{"rendered":"<h2>Vagrant\u4e09\u79cd\u7f51\u7edc\u6a21\u5f0f<\/h2>\n<h3>\u7aef\u53e3\u6620\u5c04<\/h3>\n<p>\u8f83\u4e3a\u5e38\u7528\u662f\u7aef\u53e3\u6620\u5c04\uff0c\u5c31\u662f\u5c06\u865a\u62df\u673a\u4e2d\u7684\u7aef\u53e3\u6620\u5c04\u5230\u5bbf\u4e3b\u673a\u5bf9\u5e94\u7684\u7aef\u53e3\u76f4\u63a5\u4f7f\u7528\uff0c\u5728Vagrantfile\u4e2d\u914d\u7f6e\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-yml\">config.vm.network :forwarded_port, guest: 80, host: 8080<\/code><\/pre>\n<p><code>guest: 80<\/code> \u8868\u793a\u865a\u62df\u673a\u4e2d\u768480\u7aef\u53e3\uff0c<code>host: 8080<\/code> \u8868\u793a\u6620\u5c04\u5230\u5bbf\u4e3b\u673a\u76848080\u7aef\u53e3\u3002<\/p>\n<h3>\u79c1\u6709\u7f51\u7edc<\/h3>\n<p>\u5982\u679c\u9700\u8981\u81ea\u5df1\u81ea\u7531\u7684\u8bbf\u95ee\u865a\u62df\u673a\uff0c\u4f46\u662f\u522b\u4eba\u4e0d\u9700\u8981\u8bbf\u95ee\u865a\u62df\u673a\uff0c\u53ef\u4ee5\u4f7f\u7528<code>private_network<\/code>\uff0c\u5e76\u4e3a\u865a\u62df\u673a\u8bbe\u7f6eIP\uff0c\u5728Vagrantfile\u4e2d\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-yml\">config.vm.network :private_network, ip: &quot;192.168.1.104&quot;<\/code><\/pre>\n<p>192.168.1.104 \u8868\u793a\u865a\u62df\u673a\u7684IP\uff0c\u591a\u53f0\u865a\u62df\u673a\u7684\u8bdd\u9700\u8981\u4e92\u76f8\u8bbf\u95ee\u7684\u8bdd\uff0c\u8bbe\u7f6e\u5728\u76f8\u540c\u7f51\u6bb5\u5373\u53ef<\/p>\n<h3>\u5c40\u57df\u7f51DHCP<\/h3>\n<p>\u5982\u679c\u9700\u8981\u5c06\u865a\u62df\u673a\u4f5c\u4e3a\u5f53\u524d\u5c40\u57df\u7f51\u4e2d\u7684\u4e00\u53f0\u8ba1\u7b97\u673a\uff0c\u7531\u5c40\u57df\u7f51\u8fdb\u884cDHCP\uff0c\u90a3\u4e48\u5728Vagrantfile\u4e2d\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-yml\">config.vm.network :public_network<\/code><\/pre>\n<h2>Vagrant\u5c40\u57df\u7f51\u8bbf\u95ee<\/h2>\n<p>\uff081\uff09\u4fee\u6539Vagrantfile\uff0c\u914d\u7f6e<code>public_network<\/code>\uff0c\u53d6\u6d88\u6ce8\u91ca\u5373\u53ef<\/p>\n<pre><code class=\"language-yml\">config.vm.network :public_network<\/code><\/pre>\n<p>\uff082\uff09vagrant up\u542f\u52a8\u865a\u62df\u673a\uff0c\u5728\u5bbf\u4e3b\u673a\u4e2d\u767b\u5f55<\/p>\n<ul>\n<li>Host\uff1a127.0.0.1<\/li>\n<li>Port\uff1a2222<\/li>\n<li>Username\uff1avagrant<\/li>\n<li>Password\uff1avagrant<\/li>\n<\/ul>\n<pre><code>$ sudo yum install net-tools\n$ ifconfig  \/\/\u67e5\u8be2\u5206\u914d\u7684\u5c40\u57df\u7f51IP<\/code><\/pre>\n<p>\uff083\uff09\u5c40\u57df\u7f51\u8fde\u63a5<\/p>\n<ul>\n<li>Host\uff1a192.168.1.51  \/\/ifconfig\u67e5\u8be2\u7684\u5c40\u57df\u7f51IP\u5730\u5740<\/li>\n<li>Port\uff1a22<\/li>\n<li>Username\uff1avagrant<\/li>\n<li>Password\uff1avagrant<\/li>\n<\/ul>\n<p>\uff084\uff09\u82e5SSH\u8fde\u63a5\u62a5\u9519\uff1aThe remote system refused the connection\uff0c\u5219\u5b89\u88c5SSH\u670d\u52a1<\/p>\n<pre><code>$ sudo yum install openssh-server\n$ sudo systemctl start sshd\n$ sudo systemctl status sshd<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Vagrant\u4e09\u79cd\u7f51\u7edc\u6a21\u5f0f \u7aef\u53e3\u6620\u5c04 \u8f83\u4e3a\u5e38\u7528\u662f\u7aef\u53e3\u6620\u5c04\uff0c\u5c31\u662f\u5c06\u865a\u62df\u673a\u4e2d\u7684\u7aef\u53e3\u6620\u5c04\u5230\u5bbf\u4e3b\u673a\u5bf9\u5e94\u7684\u7aef\u53e3\u76f4\u63a5\u4f7f\u7528\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[139],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-devops-base","tag-vagrant"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=433"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}