It is not illegal, but there has been some discussion I've seen that Google will associate a lot of linking between sites on same host (or same owner/IP) as link farming.
I can see their point in that those links would not be as valid as organic links from independent sources.
Whether you'd get penalised or just have low value attached to the links I can't answer. Probably the latter.