Is it possible to define a mapping hostname to IP address in Linux without root access (ie modify /etc/hosts) nor a DNS server ?
|
|
It depends on what you're trying to do. In either case, you're practically guaranteed to need to write your own code, so if you are not a programmer, you might want to either start learning how to be one, or hope you have a friend who is one. Rolling Your Own DNS Resolution InfrastructureIf you're writing your own program, you can basically bypass the system's DNS resolution entirely, and do it yourself. You see, DNS resolution is provided as a system-wide service, but there is not (usually) any restriction that prevents you from creating your own, separate, DNS resolution architecture. The actual activity of DNS resolution is "just" IP packets going over the network. So all you have to do is use an existing library that understands the DNS protocol but allows you to customize the responses or use a hosts file in a custom directory. This approach has the advantage that no "hacks" are needed, but the disadvantage is that you have to create your own program -- whether it's a scripting language or a native programming language is not relevant... either way, you need to create new software. You can't apply this hack to existing software, especially not compiled code for which you don't have the source code. An example of a C library that just does DNS message encoding/decoding is libdns from NMAP. Overriding DNS Resolution In Existing ProgramsIf you're running programs that you don't have write access to, and are setuid root, then no -- you're out of luck, unless you want to copy that program binary to another location and remove the setuid (although some programs refuse to run if they aren't setuid root). If the program you're running is not setuid root, then it should be possible. The broad strokes of what you'd have to do is to The C library functions you'll have to override with
Note that you might really confuse certain programs if you do this, because making arbitrary modifications to the return values of these functions can violate the POSIX.1-2001 standard. See RFC 2553. If you want to enable this for all programs you start, you'll have to export the Lower-level InfoThis hack is possible because setting the LD_PRELOAD environment variable to a shared library causes the dynamic linker on Linux to read the preloaded library's symbols before it reads them from any other library. So if you have a symbol (which is, essentially, a function signature) called You will have to do all of this hacking in C, most likely, due to the low level nature of the code. You can use utility libraries such as GLib to make life easier, so you don't have to invent algorithms for basic operations like string manipulation and automatically growing arrays. References |
|||||
|
