{"id":6137,"date":"2016-11-21T23:49:15","date_gmt":"2016-11-21T15:49:15","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=6137"},"modified":"2016-11-21T23:50:34","modified_gmt":"2016-11-21T15:50:34","slug":"%e5%9c%a8ubuntu-server%e4%b8%ad%e5%88%87%e6%8d%a2%e9%bb%98%e8%ae%a4%e7%9a%84network-interface","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/6137.html","title":{"rendered":"\u5728Ubuntu Server\u4e2d\u5207\u6362\u9ed8\u8ba4\u7684Network Interface"},"content":{"rendered":"<p>\u80cc\u666f<\/p>\n<p>\u6211\u7528 VirtualBox \u7ed9Ubuntu server\u7684\u865a\u62df\u673a\u914d\u7f6e\u4e86\u4e24\u4e2a\u7f51\u5361\uff0c\u4e00\u4e2a\u4e3a\u300e\u6865\u63a5\u7f51\u5361\u300f\u6a21\u5f0f\uff0c\u4e00\u4e2a\u4e3a\u300e\u7f51\u7edc\u5730\u5740\u8f6c\u6362\uff08NAT\uff09\u300f\u6a21\u5f0f\u3002<\/p>\n<p>\u901a\u8fc7\u67e5\u770b ip addr\uff0c\u7136\u540e\u624b\u52a8\u6dfb\u52a0interface\uff0c\/etc\/network\/interfaces \u6587\u4ef6\u4e2d\u6dfb\u52a0\u6ca1\u6709\u7684 interface\u3002<\/p>\n<p>\u7136\u540e\u73b0\u5728\u7684Interafce\u60c5\u51b5\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n$ ifconfig\r\nenp0s3    Link encap:Ethernet  HWaddr 08:00:27:de:db:87  \r\n          inet addr:192.168.1.120  Bcast:192.168.1.255  Mask:255.255.255.0\r\n          inet6 addr: fe80::a00:27ff:fede:db87\/64 Scope:Link\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          RX packets:727 errors:0 dropped:0 overruns:0 frame:0\r\n          TX packets:378 errors:0 dropped:0 overruns:0 carrier:0\r\n          collisions:0 txqueuelen:1000 \r\n          RX bytes:59127 (59.1 KB)  TX bytes:64152 (64.1 KB)\r\n\r\nenp0s8    Link encap:Ethernet  HWaddr 08:00:27:b8:08:5c  \r\n          inet addr:10.0.3.15  Bcast:10.0.3.255  Mask:255.255.255.0\r\n          inet6 addr: fe80::a00:27ff:feb8:85c\/64 Scope:Link\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          RX packets:2 errors:0 dropped:0 overruns:0 frame:0\r\n          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0\r\n          collisions:0 txqueuelen:1000 \r\n          RX bytes:1180 (1.1 KB)  TX bytes:1192 (1.1 KB)\r\n\r\nlo        Link encap:Local Loopback  \r\n          inet addr:127.0.0.1  Mask:255.0.0.0\r\n          inet6 addr: ::1\/128 Scope:Host\r\n          UP LOOPBACK RUNNING  MTU:65536  Metric:1\r\n          RX packets:0 errors:0 dropped:0 overruns:0 frame:0\r\n          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0\r\n          collisions:0 txqueuelen:1 \r\n          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)\r\n<\/pre>\n<p>enp0s3 \u63a5\u53e3\u4e3a\u5171\u4eab\u4e3b\u673a\u7684wifi\uff0cenp0s8\u4e3a\u76f4\u63a5\u7528\u4e3b\u673a\u7684\u7f51\u7edc\uff0c\u5305\u62ecVPN\uff0c\u53ef\u4ee5\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u5171\u4eabvpn\u3002<\/p>\n<p>\u4f46\u662f\u73b0\u5728\u9ed8\u8ba4\u4e3a\u4f7f\u7528 enp0s3 \u63a5\u53e3\u8bbf\u95ee\u5916\u7f51<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkyle@ubuntu:~$ ip route list\r\ndefault via 192.168.1.1 dev enp0s3 \r\n10.0.3.0\/24 dev enp0s8  proto kernel  scope link  src 10.0.3.15 \r\n192.168.1.0\/24 dev enp0s3  proto kernel  scope link  src 192.168.1.120 \r\n<\/pre>\n<p>\u901a\u8fc7\u67e5\u770bIP\u5730\u5740\uff0c curl ipinfo.io \uff0c\u53ef\u4ee5\u770b\u5230\u76ee\u524d\u5e76\u6ca1\u6709\u4f7f\u7528vpn\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkyle@ubuntu:~$ curl ipinfo.io\r\n{\r\n  &quot;ip&quot;: &quot;58.250.xx.xx&quot;,\r\n  &quot;hostname&quot;: &quot;No Hostname&quot;,\r\n  &quot;city&quot;: &quot;Shenzhen&quot;,\r\n  &quot;region&quot;: &quot;Guangdong&quot;,\r\n  &quot;country&quot;: &quot;CN&quot;,\r\n  &quot;loc&quot;: &quot;22.5333,114.1333&quot;,\r\n  &quot;org&quot;: &quot;AS17623 China Unicom Shenzen network&quot;\r\n}\r\n<\/pre>\n<p>\u6240\u4ee5\u9700\u8981\u628a\u7cfb\u7edf\u7684\u9ed8\u8ba4 interface \u4fee\u6539\u4e3a enp0s8 \u3002<\/p>\n<p>\u9996\u5148\u9700\u8981\u67e5\u5230 enp0s8 \u63a5\u53e3\u7684\u7f51\u5173ip\u5730\u5740\u662f\u591a\u5c11\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkyle@ubuntu:~$ ls \/var\/lib\/dhcp\/\r\ndhclient.enp0s3.leases  dhclient.enp0s8.leases\r\nkyle@ubuntu:~$ cat \/var\/lib\/dhcp\/dhclient.enp0s8.leases \r\nlease {\r\n  interface &quot;enp0s8&quot;;\r\n  fixed-address 10.0.3.15;\r\n  filename &quot;ubuntu server 16.04.pxe&quot;;\r\n  option subnet-mask 255.255.255.0;\r\n  option dhcp-lease-time 86400;\r\n  option routers 10.0.3.2;\r\n  option dhcp-message-type 5;\r\n  option dhcp-server-identifier 10.0.3.2;\r\n  option domain-name-servers 8.8.8.8,8.8.4.4;\r\n  renew 2 2016\/11\/22 00:48:08;\r\n  rebind 2 2016\/11\/22 12:29:44;\r\n  expire 2 2016\/11\/22 15:29:44;\r\n}\r\n<\/pre>\n<p>\u770b\u5230\u8fd9\u884c\uff1aoption routers 10.0.3.2 \uff0c\u5c31\u662f\u6211\u4eec\u60f3\u8981\u7684\u7f51\u5173ip\u4e86\u3002<\/p>\n<p>\u7136\u540e\u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\u8bbe\u7f6e\u9ed8\u8ba4interface \u4e3a enp0s8<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# sudo ip route change to default dev &#x5B;interface name] via &#x5B;gateway ip]\r\nsudo ip route change to default dev enp0s8 via 10.0.3.2\r\n<\/pre>\n<p>\u8fd9\u65f6\u5019\u518d\u67e5\u770b\u8def\u7531\u8868<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkyle@ubuntu:~$ ip route\r\ndefault via 10.0.3.2 dev enp0s8 \r\n10.0.3.0\/24 dev enp0s8  proto kernel  scope link  src 10.0.3.15 \r\n192.168.1.0\/24 dev enp0s3  proto kernel  scope link  src 192.168.1.120 \r\n<\/pre>\n<p>\u53d1\u73b0 default \u5df2\u7ecf\u53d8\u6210\u4e86 enp0s8\u3002<\/p>\n<p>\u518d\u67e5\u770b\u81ea\u5df1\u7684ip\u5730\u5740\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nkyle@ubuntu:~$ curl ipinfo.io\r\n{\r\n  &quot;ip&quot;: &quot;47.xx.xx.xx&quot;,\r\n  &quot;hostname&quot;: &quot;No Hostname&quot;,\r\n  &quot;city&quot;: &quot;Hong Kong&quot;,\r\n  &quot;region&quot;: &quot;HONG KONG&quot;,\r\n  &quot;country&quot;: &quot;HK&quot;,\r\n  &quot;loc&quot;: &quot;22.2833,114.1500&quot;,\r\n  &quot;org&quot;: &quot;AS45102 Alibaba (China) Technology Co., Ltd.&quot;\r\n}\r\n<\/pre>\n<p>\u5df2\u7ecf\u53d8\u6210VPN\u7684IP\u4e86\u3002<\/p>\n<p>\u53c2\u8003\uff1ahttp:\/\/www.jamesbaltar.com\/blog\/set-default-network-interface-ubuntu<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u6211\u7528 VirtualBox \u7ed9Ubuntu server\u7684\u865a\u62df\u673a\u914d\u7f6e\u4e86\u4e24\u4e2a\u7f51\u5361\uff0c\u4e00\u4e2a\u4e3a\u300e\u6865\u63a5\u7f51\u5361\u300f\u6a21\u5f0f\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-6137","post","type-post","status-publish","format-standard","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/6137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=6137"}],"version-history":[{"count":2,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/6137\/revisions"}],"predecessor-version":[{"id":6139,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/6137\/revisions\/6139"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=6137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=6137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=6137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}