コマンドラインオプションで名前解決

/etc/hostsを変更しなくても、コマンドラインオプションで名前解決できる1

–resolve

curl --resolve example.com:80:127.0.0.1 http://example.com/

これでexample.comの80番ポートへのアクセスは127.0.0.1にアクセスすることになる。

man curlの内容。

--resolve <host:port:address>
       Provide a custom address for a specific host and port pair. Using this,  you  can  make  the  curl
       requests(s)  use  a  specified  address  and prevent the otherwise normally resolved address to be
       used. Consider it a sort of /etc/hosts alternative provided on the command line. The  port  number
       should  be  the number used for the specific protocol the host will be used for. It means you need
       several entries if you want to provide address for the same host but different ports.

       The provided address set by this option will be used even if -4, --ipv4 or -6, --ipv6  is  set  to
       make curl use another IP version.

       This option can be used many times to add many host names to resolve.

       Added in 7.21.3.

7.21.3から使用可。

–connect-to

--resolveはIPを指定して接続先を変更したが、--connect-toはホスト名を指定する感じ。例えばwww.example.comというサイトがロードバランスのために実際にはload1load2load3というサーバーから成るとき、load1を指定してアクセスしたい時は

curl --connect-to www.example.com:80:load1.example.com:80 http://www.example.com

とする。

man curlの内容。

--connect-to <HOST1:PORT1:HOST2:PORT2>

       For  a  request  to  the given HOST:PORT pair, connect to CONNECT-TO-HOST:CONNECT-TO-PORT instead.
       This option is suitable to direct requests at a specific server, e.g. at a specific  cluster  node
       in  a  cluster  of servers.  This option is only used to establish the network connection. It does
       NOT affect the hostname/port that is used for TLS/SSL (e.g. SNI, certificate verification) or  for
       the  application  protocols.   "host" and "port" may be the empty string, meaning "any host/port".
       "connect-to-host" and "connect-to-port" may also be the empty string, meaning "use  the  request's
       original host/port".

       This option can be used many times to add many connect rules.

       See also --resolve and -H, --header. Added in 7.49.0.

ファイル名でダウンロードする

レスポンスタイムなどの調査

仕様書としてのcurl