有谁知道在多台机器上同步 /etc/hosts 文件的简单方法?我使用 MacBook、MacMini、Windows 机器以及 Linux 虚拟机来开发网站,因此最好让它们都具有相同的主机配置。
Windows“主机”文件编码是什么?是UTF-8吗?还是 ASCII + 系统代码页?应如何添加 IDN(带有变音符号等的国际域名)条目以及它们是否可以添加?
我不太明白socket.getfqdn()在主机上使用时所看到的内容。这是我所看到的,然后我会解释一下:
[root@myawesomehost.iscool ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@myawesomehost.iscool ~]#
[root@myawesomehost.iscool ~]#
[root@myawesomehost.iscool ~]# python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import socket
>>> socket.getfqdn()
'myawesomehost.iscool.ny.domain.com'
>>> socket.gethostname()
'myawesomehost.iscool.ny.domain.com'
>>>
[1]+ Stopped python
[root@myawesomehost.iscool ~]# vim /etc/hosts
[root@myawesomehost.iscool ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 myawesomehost.iscool.ny.domain.com
::1 localhost localhost.localdomain localhost6 …Run Code Online (Sandbox Code Playgroud) 我有一台 vagrant 机器,其 IP 地址如下:
Vagrant.configure("2") do |config|
config.vm.network :private_network, ip: 192.168.33.11
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.hostname = "my-devenv"
...
end
Run Code Online (Sandbox Code Playgroud)
一切都很好。但我对虚拟机上的 /etc/hosts 文件感到困惑:使用 localhost 和虚拟机的 IP(127.0.0.1 some-dev-site.dev vs 192.168.33.11 some-dev-site.dev)有什么区别?
127.0.0.1 localhost
127.0.0.1 some-dev-site.dev
192.168.33.11 some-dev-site.dev
Run Code Online (Sandbox Code Playgroud) 所以我只是想修改家庭成员手机上的主机文件。我已将手机置于调试模式并提取主机文件,对其进行编辑,但是当我尝试推送它时,我收到消息“adb:错误:无法将‘D:/hosts\hosts’复制到‘/system’ /etc/hosts/hosts':远程无法创建文件:不是目录”
这是我使用过的命令:
adb pull /system/etc/hosts D:\hosts
/system/etc/hosts: 1 file pulled. 0.0 MB/s (56 bytes in 0.003s)
adb push D:\hosts /system/etc/
adb: error: failed to copy 'D:\hosts\hosts' to '/system/etc/hosts/hosts': remote couldn't create file: Not a directory
Run Code Online (Sandbox Code Playgroud)
这是我第一次使用 android debug/adb,我读过的其他内容都没有帮助。提前致谢。
编辑:所以我取得了一些进展。我意识到主机文件不在主机目录中,所以我将其更改为adb push D:\hosts /system/etc仍然不起作用,但adb push D:\hosts\hosts /system/etc给了我响应adb: error: failed to copy 'D:\hosts\hosts' to '/system/etc/hosts': remote couldn't create file: Read-only file system 所以看起来我的问题现在在adb shell chmod
EDIT2:所以经过一些更多的研究,我在 Android 上发现了这个只读文件系统。当我尝试时,mount -o rw,remount /system我得到了mount: …
我创建了一个基本的 Express 应用程序
const express = require('express');
const app = express();
app.get("*", (req, res) => {;
res.contentType('html');
res.send("HELLO FROM WSL");
});
const port = 80
app.listen(port);
Run Code Online (Sandbox Code Playgroud)
然后我添加以下条目c:\windows\system32\drivers\etc\hosts
127.0.0.1 custom.local
Run Code Online (Sandbox Code Playgroud)
然后我关闭 wslwsl --shutdown并重新打开以启动我的 Express 应用程序。
如果我从 WSL ( cat /etc/hosts) 检查主机文件,我得到以下结果
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1 localhost
127.0.1.1 LAPTOP-ZECKA.localdomain LAPTOP-ZECKA
127.0.0.1 custom.local
Run Code Online (Sandbox Code Playgroud)
然后我去http://custom.local …
添加-Djdk.net.hosts.file属性后,我的应用程序无法解析本地计算机的名称。当我提供的主机文件中找不到任何内容时,有没有办法让它回退到默认分辨率?
我遇到了hosts文件和PHP的问题.运行PHP代码时root,将读取/ etc/hosts中的条目.但不是以我的用户或apache运行代码时.
root@server:/# cat /etc/hosts
127.0.0.1 mydomain.com
root@server:/# php -r "echo gethostbyname('mydomain.com');"
127.0.0.1
markus@server:/$ php -r "echo gethostbyname('mydomain.com');"
xxx.xxx.xxx.xxx
Run Code Online (Sandbox Code Playgroud)
知道为什么会这样吗?
Meteor如何处理多个虚拟主机?
www.Some-Client-Domain.com - > www.Our-CName-URL.com - > Meteor app.
我们需要Meteor应用程序提供相同的站点/应用程序,但需要特定于所请求的原始URL的数据(Some-Client-Domain.com).
在我们当前的原型中,我们在Rails前面有NGINX,并且有几种不同的方法可以做到这一点,包括将NGINX连接到数据库以获取MANY虚拟主机的定义.这很好用,因为如果新客户注册,我们可以更新数据库,然后NGINX立即知道该虚拟主机,而无需进一步的NGINX配置.
如何在Meteor中完成?
谢谢!
为了支持一些旧的软件解决方案,我需要绑定我的容器的hostname到127.0.0.1,让我有这样的事情:
$ hostname
4e84a7ae5f92
$ cat /etc/hosts | grep 127.0.0.1
127.0.0.1 localhost 4e84a7ae5f92
Run Code Online (Sandbox Code Playgroud)
最好的情况是在Dockerfile中做,但由于docker build构建了一个图像(而不是容器),它似乎不太现实.
此外,如果我尝试sed在正在运行的容器中执行此操作,我最终会收到错误:
$ sed -i '/^127\.0\.0\.1.*/ s/$/ '$(hostname)'/' /etc/hosts
sed: cannot rename /etc/sedC5PkA2: Device or resource busy
Run Code Online (Sandbox Code Playgroud)
我能做什么 ?